제출 #1064391

#제출 시각아이디문제언어결과실행 시간메모리
1064391anango곤돌라 (IOI14_gondola)C++17
90 / 100
270 ms262144 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000009; signed valid(signed n, signed inputSeq[]) { vector<int> pos(n,-1); set<int> seen; for (int i=0; i<n; i++) { if (inputSeq[i]<=n) { pos[inputSeq[i]-1] = i; } if (seen.count(inputSeq[i]-1)) { return 0; } seen.insert(inputSeq[i]-1); } set<int> S; for (int i=0; i<n; i++) { if (pos[i]!=-1) { S.insert((pos[i]-i+n)%n); } } return S.size()<=1; } //---------------------- signed replacement(signed n, signed gondolaSeq[], signed replacementSeq[]) { vector<pair<int,int>> posindex; vector<int> actual(n,-1); for (int i=0; i<n; i++) { if (gondolaSeq[i]<=n) { for (int j=0; j<n; j++) { actual[j] = (gondolaSeq[i]-1+j-i+3*n)%n; } break; } } if (actual[0]==-1) { for (int i=0; i<n; i++) actual[i] = i; } for (int i=0; i<n; i++) { //cout << actual[i] <<" "; } //cout << endl; for (int i=0; i<n; i++) { posindex.push_back({gondolaSeq[i]-1,i}); } sort(posindex.begin(), posindex.end()); vector<int> repl; int cur = n; for (int i=0; i<posindex.size(); i++) { while (posindex[i].first>=cur) { repl.push_back(actual[posindex[i].second]); actual[posindex[i].second] = cur; cur++; } } for (int i=0; i<repl.size(); i++) { replacementSeq[i] = repl[i]+1; } //cout << "done " << repl.size() << endl; return repl.size(); } //---------------------- signed countReplacement(signed n, signed inputSeq[]) { vector<int> pos(n,-1); set<int> seen; for (int i=0; i<n; i++) { if (inputSeq[i]<=n) { pos[inputSeq[i]-1] = i; } if (seen.count(inputSeq[i]-1)) { return 0; } seen.insert(inputSeq[i]-1); } set<int> S; for (int i=0; i<n; i++) { if (pos[i]!=-1) { S.insert((pos[i]-i+n)%n); } } if (S.size()>1) { return 0; } int prod = 1; vector<pair<int,int>> posindex; vector<int> actual(n,-1); for (int i=0; i<n; i++) { if (inputSeq[i]<=n) { for (int j=0; j<n; j++) { actual[j] = (inputSeq[i]-1+j-i+3*n)%n; } break; } } if (actual[0]==-1) { prod = n; //multiply by n at the end for (int i=0; i<n; i++) actual[i] = i; } for (int i=0; i<n; i++) { //cout << actual[i] <<" "; } //cout << endl; for (int i=0; i<n; i++) { posindex.push_back({inputSeq[i]-1,i}); } sort(posindex.begin(), posindex.end()); vector<int> repl; int cur = n; for (int i=0; i<posindex.size(); i++) { while (posindex[i].first>=cur) { repl.push_back(actual[posindex[i].second]); actual[posindex[i].second] = cur; if (posindex[i].first>cur) { prod*=n-i; prod%=MOD; } cur++; } } //cout << "done " << repl.size() << endl; return (signed)prod; }

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:54:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i=0; i<posindex.size(); i++) {
      |                   ~^~~~~~~~~~~~~~~~
gondola.cpp:61:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i=0; i<repl.size(); i++) {
      |                   ~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:20: warning: comparison of integer expressions of different signedness: 'long long 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<posindex.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...