Submission #250665

#TimeUsernameProblemLanguageResultExecution timeMemory
250665hhh07Gondola (IOI14_gondola)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <utility> #include <set> #include <cmath> #include <climits> #include <cstring> #include <stdio.h> #include <assert.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<ll, ll> ii; ll MOD = 1e9 + 9; ll stepen(int x, int st){ ll res = 1; for (int i = 1; i <= st; i++){ res *= x; res %= MOD; if (i*2 <= st){ i *= 2; res *= res; res %= MOD; } } return res; } int valid(int n, int x[]){ int j = -1; for (int i = 0; i < n; i++){ if (x[i] > n) continue; j = i; break; } if (j == -1) return true; vector<bool> visited(250001, 0); for (int i = 0; i < n; i++){ if (visited[x[i]]) return false; visited[x[i]] = true; if (j > i){ int moze = x[j] - (j - i); if (moze < 1) moze += n; if (x[i] <= n && moze != x[i]){ return false; } } else{ int moze = x[j] + (i - j); if (moze > n) moze -= n; if (x[i] <= n && moze != x[i]){ return false; } } } return true; } int replacement(int n, int x[], int y[]){ vector<ii> t; vi visited(250001, false); int j = 0; for (int i = 0; i < n; i++){ visited[x[i]] = true; if (x[i] > n) t.push_back(make_pair(x[i], i)); else j = i; } sort(t.begin(), t.end()); for (int i = 0; i < n; i++){ if (j > i){ int moze = x[j] - (j - i); if (moze < 1) moze += n; x[i] = moze; } else{ int moze = x[j] + (i - j); if (moze > n) moze -= n; x[i] = moze; } } vi res; for (int i = 0; i < t.size(); i++){ int curr = t[i].first, idx = t[i].second; for (int j = x[idx]; j <= curr; j++){ if (!visited[j]) res.push_back(j); visited[j] = true; } visited[curr] = true; } for (int i = 0; i < res.size(); i++) y[i] = res[i]; return res.size(); } int countReplacement(int n, int x[]){ bool k = valid(n, x); if (!k) return 0; vector<ii> t; int j = 0; for (int i = 0; i < n; i++){ if (x[i] > n) t.push_back(make_pair(x[i], i)); else j = i; } for (int i = 0; i < n; i++){ if (j > i){ int moze = x[j] - (j - i); if (moze < 1) moze += n; x[i] = moze; } else{ int moze = x[j] + (j - i); if (moze > n) moze -= n; x[i] = moze; } } sort(t.begin(), t.end()); ll res = 1; int curr = t.size(); int prev = n; for (int i = 0; i < t.size(); i++){ res *= stepen(t.size() - i, t[i].first - prev - 1); res %= MOD; prev = t[i].first; } return res; } int gondolaSequence[100001]; int replacementSequence[250001]; int main() { int i, n, tag; int nr; assert(scanf("%d", &tag)==1); assert(scanf("%d", &n)==1); for(i=0;i< n;i++) assert( scanf("%d", &gondolaSequence[i]) ==1); switch (tag){ case 1: case 2: case 3: printf("%d\n", valid(n, gondolaSequence)); break; case 4: case 5: case 6: nr = replacement(n, gondolaSequence, replacementSequence); printf("%d ", nr); if (nr > 0) { for (i=0; i<nr-1; i++) printf("%d ", replacementSequence[i]); printf("%d\n", replacementSequence[nr-1]); } else printf("\n"); break; case 7: case 8: case 9: case 10: printf("%d\n", countReplacement(n, gondolaSequence)); break; } return 0; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:98:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < t.size(); i++){
                     ~~^~~~~~~~~~
gondola.cpp:107:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < res.size(); i++)
                     ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:143:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < t.size(); i++){
                     ~~^~~~~~~~~~
gondola.cpp:141:9: warning: unused variable 'curr' [-Wunused-variable]
     int curr = t.size();
         ^~~~
/tmp/ccETULSL.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccrOkOpc.o:gondola.cpp:(.text.startup+0x0): first defined here
/tmp/ccETULSL.o:(.bss+0xf4260): multiple definition of `gondolaSequence'
/tmp/ccrOkOpc.o:(.bss+0xf4260): first defined here
/tmp/ccETULSL.o:(.bss+0x0): multiple definition of `replacementSequence'
/tmp/ccrOkOpc.o:(.bss+0x0): first defined here
/tmp/ccETULSL.o: In function `main':
grader.cpp:(.text.startup+0xc3): undefined reference to `countReplacement'
grader.cpp:(.text.startup+0xe2): undefined reference to `valid'
grader.cpp:(.text.startup+0x106): undefined reference to `replacement'
collect2: error: ld returned 1 exit status