이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
int valid(int n, int a[])
{
map<int,bool> use;
pair<int,int> mn = {1e9, 1e9};
for(int i = 0; i < n; i++)
{
mn = min(mn, {a[i], i});
if(use.count(a[i])) return 0;
use[a[i]] = true;
}
if(mn.f > n) return 1;
if(mn.f < 1) return 0;
for(int i = 0; i < n; i++)
{
if(a[(mn.s + i) % n] <= n && a[(mn.s + i) % n] != (mn.f + i + n - 1) % n + 1)
return 0;
}
return 1;
}
//----------------------
int to[250005], use[250005];
int replacement(int n, int a[], int ans[])
{
int mx = 0;
int cur = -1, idx = 0;
pair<int,int> mn = {1e9, 1e9};
for(int i = 0; i < n; i++)
mn = min(mn, {a[i], i}), mx = max(mx, a[i]);
for(int i = 0; i < n; i++)
if(a[(mn.s + i) % n] != (mn.f + i + n - 1) % n + 1)
{
to[(mn.f + i + n - 1) % n + 1] = a[(mn.s + i) % n];
if(a[(mn.s + i) % n] == mx)
cur = (mn.f + i + n - 1) % n + 1;
else
use[a[(mn.s + i) % n]] = (mn.f + i + n - 1) % n + 1;
}
for(int i = n + 1; i <= mx; i++)
{
if(use[i])
ans[idx++] = use[i];
else
ans[idx++] = cur, cur = i;
}
return idx;
}
//----------------------
int fast_pow(long long base, long long pw)
{
if(pw == 0) return 1;
long long ret = 1ll;
long long mul = base;
while(pw > 0)
{
if(pw & 1)
ret = (ret * mul) % mod;
mul = (mul * mul) % mod;
pw >>= 1;
}
return ret;
}
int countReplacement(int n, int a[])
{
if(!valid(n, a)) return 0;
int mx = 0;
vector<int> v;
long long cal = 1ll;
for(int i = 0; i < n; i++)
if(a[i] > n) v.pb(a[i]), use[a[i]] = 1;
v.pb(n);
sort(all(v));
for(int i = 1; i < sz(v); i++)
{
if(v[i] - v[i - 1] - 1 == 0) continue;
cal *= fast_pow((sz(v) - i), (v[i] - v[i - 1] - 1));
cal %= mod;
}
return cal;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:81:9: warning: unused variable 'mx' [-Wunused-variable]
81 | int mx = 0;
| ^~
# | 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... |