Submission #64754
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <bits/stdc++.h> //{ START using namespace std; #define int int64_t #define rep(i, a, n) for (int i = (a); i < (n); ++i) #define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i) #define arep(i, x) for (auto &&i : (x)) #define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i) #define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i) //降順はgreater<T>() #define all(x) (x).begin(), (x).end() #define rv(s) reverse((s).begin(), (s).end()) // gcd lcmはそのままok #define gcd(a, b) __gcd(a, b) #define bits(n) (1LL << (n)) #define pcnt(x) __builtin_popcountll(x) //配列内等要素削除 #define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end()) #define Fixed(n) fixed << setprecision(n) //総和 #define sowa(n) (((n) * ((n) + 1)) / 2) #define updiv(a, b) ((a + b - 1) / b) #define cauto const auto & using P = pair< int , int >; using Graph = vector<vector<P>>; template < class T> //昇順 using min_heap = priority_queue<T, vector<T>, greater<T>>; template < class T> //降順 using max_heap = priority_queue<T>; template < class A, class B> using umap = unordered_map<A, B>; template < class A> using uset = unordered_set<A>; template < typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { //多次元初期化 std::fill((T *)array, (T *)(array + N), val); } template < class A, class B> bool chmax(A &a, const B &b) { //最大値更新 返り値はbool if (a < b) { a = b; return 1; } return 0; } template < class A, class B> bool chmin(A &a, const B &b) { //最小値更新 返り値はbool int a, b; if (b < a) { a = b; return 1; } return 0; } int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1}; constexpr int INF = 0x3f3f3f3f; constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9 + 7; constexpr int mod2 = 998244353; //} END signed main( void ) { cin.tie(nullptr); ios_base::sync_with_stdio( false ); int n; cin>>n; vector< int > x(n); set< int > se; int cnt = 0; arep(i,x) cin>>i; rep(i,0,n){ if (x[i] - i - 1 == 0) ++cnt; else se.insert( abs (x[i]-i-1)); } if (cnt == n) cout<<n-1<< '\n' ; else { int ans = *se.begin(); arep(i,se) ans = gcd(ans, i); cout<<ans<< '\n' ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1419 - Permutation Sort |
ユーザー名 | immunity |
投稿日時 | 2020-11-16 18:33:43 |
言語 | C++17 |
状態 | Accepted |
得点 | 4 |
ソースコード長 | 2370 Byte |
最大実行時間 | 221 ms |
最大メモリ使用量 | 17908 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 4 / 4 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 44 ms | 3420 KB |
1
|
in02.txt | AC | 34 ms | 2376 KB |
1
|
in03.txt | AC | 140 ms | 12904 KB |
1
|
in04.txt | AC | 105 ms | 10412 KB |
1
|
in05.txt | AC | 50 ms | 4484 KB |
1
|
in06.txt | AC | 52 ms | 4496 KB |
1
|
in07.txt | AC | 76 ms | 4376 KB |
1
|
in08.txt | AC | 177 ms | 13272 KB |
1
|
in09.txt | AC | 60 ms | 4424 KB |
1
|
in10.txt | AC | 50 ms | 4304 KB |
1
|
in11.txt | AC | 49 ms | 4320 KB |
1
|
in12.txt | AC | 43 ms | 4336 KB |
1
|
in13.txt | AC | 47 ms | 4476 KB |
1
|
in14.txt | AC | 148 ms | 10944 KB |
1
|
in15.txt | AC | 220 ms | 17756 KB |
1
|
in16.txt | AC | 221 ms | 17908 KB |
1
|
in17.txt | AC | 59 ms | 4484 KB |
1
|
in18.txt | AC | 118 ms | 5900 KB |
1
|
in19.txt | AC | 18 ms | 528 KB |
1
|
in20.txt | AC | 21 ms | 608 KB |
1
|
in21.txt | AC | 17 ms | 688 KB |
1
|
in22.txt | AC | 51 ms | 4864 KB |
1
|
in23.txt | AC | 50 ms | 4556 KB |
1
|
in24.txt | AC | 46 ms | 4436 KB |
1
|
in25.txt | AC | 44 ms | 4448 KB |
1
|
in26.txt | AC | 53 ms | 4460 KB |
1
|
in27.txt | AC | 45 ms | 4448 KB |
1
|
in28.txt | AC | 47 ms | 4568 KB |
1
|
in29.txt | AC | 46 ms | 5064 KB |
1
|
in30.txt | AC | 50 ms | 5108 KB |
1
|
sample01.txt | AC | 22 ms | 800 KB |
1
|
sample02.txt | AC | 21 ms | 756 KB |
1
|