제출 #569335

#제출 시각아이디문제언어결과실행 시간메모리
569335Valaki2곤돌라 (IOI14_gondola)C++14
75 / 100
36 ms4596 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define fi first #define se second signed valid(signed n, signed inputSeq[]) { set<int> nums; for(int i = 0; i < n; i++) { nums.insert(inputSeq[i]); } if(nums.size() < n) { return 0; } int pos = -1; for(int i = 0; i < n; i++) { if(inputSeq[i] <= n) { pos = i; } } if(pos == -1) { return 1; } for(int i = 0; i < pos; i++) { if(inputSeq[i] <= n) { if(pos - i != (inputSeq[pos] - inputSeq[i] + n) % n) { return 0; } } } return true; } //---------------------- signed replacement(signed n, signed gondolaSeq[], signed replacementSeq[]) { vector<pair<int, int> > v(n, mp(0, 0)); for(int i = 0; i < n; i++) { v[i] = mp(gondolaSeq[i], i); } sort(v.begin(), v.end()); vector<int> lab(n, 0); int pos = 0, val = 1; for(int i = 0; i < n; i++) { if(gondolaSeq[i] <= n) { pos = i; val = gondolaSeq[i]; } } for(int i = pos; i < pos + n; i++) { lab[i % n] = val; val++; while(val > n) { val -= n; } } int last = n; vector<int> ans; for(int i = 0; i < n; i++) { if(v[i].fi > n) { for(int j = last + 1; j <= v[i].fi; j++) { ans.pb(lab[v[i].se]); lab[v[i].se] = n + ans.size(); } last = v[i].fi; } } int l = ans.size(); for(int i = 0; i < l; i++) { replacementSeq[i] = ans[i]; } return l; } //---------------------- const int mod = 1e9 + 9; int add(int a, int b) { return (a + b) % mod; } int subt(int a, int b) { return (a - b + mod) % mod; } int mult(int a, int b) { return (a * b) % mod; } int sq(int a) { return mult(a, a); } int power(int a, int b) { if(b == 0) { return 1; } if(b % 2 == 1) { return a * power(a, b - 1); } else { return sq(power(a, b / 2)); } } signed countReplacement(signed n, signed inputSeq[]) { bool factorial = false; if(true) { set<int> nums; for(int i = 0; i < n; i++) { nums.insert(inputSeq[i]); } if(nums.size() < n) { return 0; } int pos = -1; for(int i = 0; i < n; i++) { if(inputSeq[i] <= n) { pos = i; } } if(pos != -1) { for(int i = 0; i < pos; i++) { if(inputSeq[i] <= n) { if(pos - i != (inputSeq[pos] - inputSeq[i] + n) % n) { return 0; } } } } else { factorial = true; } } sort(inputSeq, inputSeq + n); int ans = 1; if(factorial) { for(int i = 1; i <= n; i++) { ans = mult(ans, i); } } for(int i = 1; i < n; i++) { if(inputSeq[i] > n) { ans = mult(ans, power(n - i, inputSeq[i] - max(n, inputSeq[i - 1]) - 1)); } } if(inputSeq[0] > n) { ans = mult(ans, power(n, inputSeq[0] - n - 1)); } return ans; }

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

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:16:20: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     if(nums.size() < n) {
      |        ~~~~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:24: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  117 |         if(nums.size() < n) {
      |            ~~~~~~~~~~~~^~~
#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...