Submission #296202

#TimeUsernameProblemLanguageResultExecution timeMemory
296202arayiGondola (IOI14_gondola)C++17
100 / 100
28 ms2932 KiB
#include <bits/stdc++.h> #include "gondola.h" #define ad push_back #define MP make_pair #define fr first #define sc second #define lli long long int using namespace std; const lli mod = 1000000009; const int N = 3e5 + 20; bool col[N]; int valid(int n, int inputSeq[]) { vector <int> a; for (int i = 0; i < n; i++) a.ad(inputSeq[i]); for (int i = 0; i < n; i++) a.ad(inputSeq[i]); int i1 = -1; for (int i = 0; i < n; i++) { if(col[a[i]]) return 0; col[a[i]] = true; if(a[i] <= n) { i1 = (i - a[i] + 1 + n) % n; } } if(i1 == -1) return 1; for (int i = i1; i < i1 + n; i++) { if(a[i] > n) continue; if(i - i1 + 1 != a[i]) return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector <int> a, pat; for (int i = 0; i < n; i++) a.ad(gondolaSeq[i]); for (int i = 0; i < n; i++) a.ad(gondolaSeq[i]); int i1 = 0; for (int i = 0; i < n; i++) { if(a[i] <= n) i1 = (i - a[i] + 1 + n) % n; } vector <pair<int, int> > fp; int nw = n + 1; for (int i = i1; i < i1 + n; i++) { fp.ad(MP(a[i], i - i1 + 1)); } sort(fp.begin(), fp.end()); for (int i = 0; i < fp.size(); i++) { while(nw <= fp[i].fr) { pat.ad(fp[i].sc); fp[i].sc = nw; nw++; } } for (int i = 0; i < pat.size(); i++) replacementSeq[i] = pat[i]; return (int)pat.size(); } lli bp(lli a, lli b = mod - 2LL) { lli ret = 1; while(b) { if(b & 1) ret *= a, ret %= mod; a *= a, a %= mod; b >>= 1; } return ret; } int countReplacement(int n, int inputSeq[]) { vector <lli> fp; for (int i = 0; i < n; i++) if(inputSeq[i] > n) fp.ad(inputSeq[i]); lli nw = n + 1; lli m = fp.size(); sort(fp.begin(), fp.end()); lli pat = 1; if(m == n) pat = n; for (lli i = 0; i < m; i++) { //cout << i << endl; pat *= bp(m - i, fp[i] - nw); pat %= mod; nw = fp[i]+ 1; } return pat; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for (int i = 0; i < fp.size(); i++)
      |                   ~~^~~~~~~~~~~
gondola.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int i = 0; i < pat.size(); i++) replacementSeq[i] = pat[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...