Submission #172526

#TimeUsernameProblemLanguageResultExecution timeMemory
172526DS007Gondola (IOI14_gondola)C++14
60 / 100
161 ms9196 KiB
#include <bits/stdc++.h> #include <gondola.h> using namespace std; int valid(int n, int inputSeq[]) { set<int> done; map<int, int> pos; for (int i = 0; i <= n; i++) pos[i] = -1; vector<int> a; int check = 1; for (int i = 0; i < n; i++) { if (done.count(inputSeq[i])) check = 0; done.insert(inputSeq[i]); if (inputSeq[i] <= n) a.push_back(inputSeq[i]), pos[inputSeq[i]] = i; } int ind = -1, val = n + 1; for (int i = 0; i < a.size(); i++) { if (a[i] < val) val = a[i], ind = i; } if (ind == -1) return check; for (int i = 0, j = ind + 1; i < a.size() - 1; i++, j++) { if (j == a.size()) j = 0; assert(j < a.size()); if (a[j] <= val) check = 0; val = a[j]; } int last = 1; while (last <= n && pos[last] == -1) last++; for (int i = last + 1; i <= n; i++) { assert(i <= n && last <= n); if (pos[i] == -1) continue; if (i - last != pos[i] - pos[last] && i - last != pos[i] + n - pos[last]) check = 0; last = i; } return check; } int initial[100000]; int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int check = -1; for (int i = 0; i < n; i++) if (gondolaSeq[i] <= n) check = i; if (check == -1) { for (int i = 0; i < n; i++) initial[i] = i + 1; } else { for (int i = 0, j = check, k = gondolaSeq[j]; i < n; i++, j++, k++) { if (k == n + 1) k = 1; if (j == n) j = 0; initial[j] = k; } } map<int, int> m; for (int i = 0; i < n; i++) if (gondolaSeq[i] > n) m[gondolaSeq[i]] = i; int last = n + 1, c = 0; for (auto i : m) { for (; last <= i.first; last++) { replacementSeq[c++] = initial[i.second]; initial[i.second] = last; } } return c; } int countReplacement(int n, int inputSeq[]) { return 1; } /*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 valid(int, int*)':
gondola.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++) {
                     ~~^~~~~~~~~~
gondola.cpp:29:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0, j = ind + 1; i < a.size() - 1; i++, j++) {
                                  ~~^~~~~~~~~~~~~~
gondola.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (j == a.size())
             ~~^~~~~~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from gondola.cpp:1:
gondola.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         assert(j < a.size());
                ~~^~~~~~~~~~
#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...