Submission #129467

#TimeUsernameProblemLanguageResultExecution timeMemory
129467antimirageGondola (IOI14_gondola)C++14
60 / 100
27 ms6108 KiB
#include "gondola.h" //#include "grader.cpp" #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int b[N], ind[N], mx, sz, cnt[N], mod = 1e9 + 9; int valid(int n, int a[]) { int pos = -1; for (int i = 0; i < n; i++) { if (a[i] <= n) { pos = i; } cnt[a[i]]++; if (cnt[a[i]] > 1) return 0; } if (pos == -1) { return 1; } else { assert(a[pos] <= n); int cn = a[pos]; for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) { cn++; if (cn > n) cn -= n; if (a[i] > n) { continue; } if (a[i] != cn) { return 0; } } } return 1; } int replacement(int n, int a[], int ans[]) { memset(ind, -1, sizeof(ind)); int pos = -1; for (int i = 0; i < n; i++) { if (a[i] <= n) { pos = i; } if (a[i] > a[mx]) { mx = i; } ind[a[i]] = i; } if (pos == -1) { for (int i = 0; i < n; i++) { b[i] = i + 1; } } else { int cn = a[pos]; b[pos] = a[pos]; for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) { cn++; if (cn > n) cn -= n; b[i] = cn; } } for (int i = n + 1; i <= a[mx]; i++) { if (ind[i] == -1) { ans[sz++] = b[mx]; b[mx] = i; } else { ans[sz++] = b[ind[i]]; b[ind[i]] = i; } } return sz; } int countReplacement(int n, int a[]) { if (valid(n, a) == 0) return 0; int pos = -1; long long res = 1, val = 1; for (int i = 0; i < n; i++) { if (a[i] <= n) { pos = i; } } if (pos == -1) { for (int i = 0; i < n; i++) { b[i] = i + 1; res *= (i + 1); res %= mod; } } else { int cn = a[pos]; b[pos] = a[pos]; for (int i = (pos + 1) % n; i != pos; i = (i + 1) % n) { cn++; if (cn > n) cn -= n; b[i] = cn; } sort(a, a + n); int j = 0; for (int i = n + 1; i <= a[n - 1]; i++) { while (a[j] < i) j++; if (ind[i] == -1) { res *= (n - j); res %= mod; } } } return res; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:89:21: warning: unused variable 'val' [-Wunused-variable]
  long long res = 1, val = 1;
                     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...