Submission #172520

#TimeUsernameProblemLanguageResultExecution timeMemory
172520DS007Gondola (IOI14_gondola)C++14
30 / 100
168 ms9148 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 replacement(int n, int gondolaSeq[], int replacementSeq[]) { set<int> done; for (int i = 0; i < n; i++) done.insert(gondolaSeq[i]); int c = 0; for (int i = 1; i <= *done.rbegin(); i++) { if (done.count(i) == 0) replacementSeq[c++] = i; } 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...