이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[])
{
long long offset = -1;
unordered_map<int, bool> odw;
for(long long i = 0; i < n; i++){
if(odw[inputSeq[i]]) return 0;
odw[inputSeq[i]] = true;
if(inputSeq[i]<=n){
long long tmp = (n+inputSeq[i]-i)%n;
if(offset==-1) offset = tmp;
if(tmp!=offset) return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
long long offset = -1;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> q;
for(long long i = 0; i < n; i++){
if(gondolaSeq[i]<=n){
long long tmp = (n+gondolaSeq[i]-i-1)%n;
if(offset==-1) offset = tmp;
}else{
q.push(make_pair(gondolaSeq[i], i));
}
}
if(offset==-1) offset=0;
for(long long i = 0; i < n; i++){
gondolaSeq[i] = 1+(i+offset)%n;
}
long long cur = n+1;
for(long long i = 0; !q.empty(); i++){
if(gondolaSeq[q.top().second] < q.top().first){
replacementSeq[i] = gondolaSeq[q.top().second];
gondolaSeq[q.top().second] = cur;
cur++;
}else{
q.pop();
i--;
}
}
return cur-n-1;
return -2;
}
//----------------------
long long mod = 1e9+9;
long long pot(long long a, long long b){
if(b==0) return 1;
if(b%2==0){
long long cur = pot(a, b/2);
return (cur*cur)%mod;
}else return (a*pot(a, b-1))%mod;
}
int countReplacement(int n, int inputSeq[])
{
vector<long long> tab;
long long offset = -1;
long long wyn = 1;
long long cnt = 0;
unordered_map<int, bool> odw;
for(long long i = 0; i < n; i++){
if(odw[inputSeq[i]]) return 0;
odw[inputSeq[i]] = true;
if(inputSeq[i]<=n){
long long tmp = (n+inputSeq[i]-i)%n;
if(offset==-1) offset = tmp;
if(tmp!=offset) return 0;
}else{
cnt++;
tab.push_back(inputSeq[i]);
}
}
sort(tab.begin(), tab.end());
long long cur = n+1;
for(long long i = 0; i < tab.size(); i++){
wyn*=pot(cnt, tab[i]-cur);
wyn%=mod;
cur=tab[i]+1;
cnt--;
}
return wyn;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:90:25: 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]
90 | for(long long i = 0; i < tab.size(); i++){
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |