Submission #1063723

#TimeUsernameProblemLanguageResultExecution timeMemory
1063723pawnedGondola (IOI14_gondola)C++17
55 / 100
18 ms5972 KiB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; #include "gondola.h" int valid(int N, int inputSeq[]) { vi a; for (int i = 0; i < N; i++) { a.pb(inputSeq[i] - 1); } int fpos = -1; // fixed position int fval = -1; // fixed val at position for (int i = 0; i < N; i++) { if (a[i] < N) { fpos = i; fval = a[i]; } } vi b; if (fval > fpos) { int s = fval - fpos; for (int i = N - s; i < N; i++) { b.pb(a[i]); } for (int i = 0; i < N - s; i++) { b.pb(a[i]); } } else { int s = fpos - fval; for (int i = s; i < N; i++) { b.pb(a[i]); } for (int i = 0; i < s; i++) { b.pb(a[i]); } } for (int i = 0; i < N; i++) { if (b[i] < N) { if (b[i] != i) return 0; } } // all values must be diff set<int> allv; for (int x : b) allv.insert(x); if (allv.size() != N) return 0; return 1; } int replacement(int N, int gondolaSeq[], int replacementSeq[]) { vi a; for (int i = 0; i < N; i++) { a.pb(gondolaSeq[i] - 1); } int fpos = -1; // fixed position int fval = -1; // fixed val at position for (int i = 0; i < N; i++) { if (a[i] < N) { fpos = i; fval = a[i]; } } vi b; if (fpos == -1) { b = a; } else if (fval > fpos) { int s = fval - fpos; for (int i = N - s; i < N; i++) { b.pb(a[i]); } for (int i = 0; i < N - s; i++) { b.pb(a[i]); } } else { int s = fpos - fval; for (int i = s; i < N; i++) { b.pb(a[i]); } for (int i = 0; i < s; i++) { b.pb(a[i]); } } /* cout<<"b: "; for (int x : b) cout<<x<<" "; cout<<endl;*/ // replace 0, 1, ..., N - 1 with b vector<ii> rep; for (int i = 0; i < N; i++) { if (b[i] != i) rep.pb({b[i], i}); } sort(rep.begin(), rep.end()); /* cout<<"rep: "; for (ii p : rep) cout<<"("<<p.fi<<", "<<p.se<<"); "; cout<<endl;*/ if (rep.size() == 0) { // just 0 to N - 1 return 0; } int curr = N - 1; vi ans; for (int i = 0; i < rep.size(); i++) { ans.pb(rep[i].se); for (int j = curr + 1; j < rep[i].fi; j++) { ans.pb(j); } curr = rep[i].fi; } int K = ans.size(); for (int i = 0; i < K; i++) { replacementSeq[i] = ans[i] + 1; } return K; } int countReplacement(int N, int inputSeq[]) { return -3; } // subtasks 1, 2, 3: check validity

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:57:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |  if (allv.size() != N)
      |      ~~~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:117:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |  for (int i = 0; i < rep.size(); i++) {
      |                  ~~^~~~~~~~~~~~
#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...