이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#pragma comment(linker, "/STACK:16777216")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define forn(j, i, n) for(int i = j; i <= n; ++i)
#define FOR(j, i, n) for(int i = j; i < n; ++i)
#define nfor(j, i, n) for(int i = n; i >= j; --i)
#define IOS ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define all(v) v.begin(), v.end()
#define pb push_back
const int maxn = 3e5+100;
//#define int ll
#define pii pair <int, int>
int inf = 1e9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[maxn], was[maxn], b[maxn];
int valid(int n, int inputSeq[])
{
forn(1, i, n)
{
a[i] = inputSeq[i-1];
was[a[i]]++;
if(was[a[i]] >= 2)
{
return 0;
}
}
int start = -1;
forn(1, i, n)
{
if(a[i] <= n)
{
start = i - a[i] + 1;
break;
}
}
if(start == -1) return 1;
forn(1, i, n)
{
b[(i-start+n)%n+1] = a[i];
}
forn(1, i, n)
{
if(b[i] > n) continue;
if(b[i] != i) return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
forn(1, i, n)
{
a[i] = gondolaSeq[i-1];
}
int start = -1;
forn(1, i, n)
{
if(a[i] <= n)
{
start = i - a[i] + 1;
break;
}
}
if(start == -1)
{
set <pii> st;
forn(1, i, n)
{
if(a[i] > n)
{
st.insert({a[i], i});
}
}
int cur = 0;
while(st.size())
{
replacementSeq[cur] = st.begin()->s;
cur++;
while(n + cur < st.begin()->f)
{
replacementSeq[cur] = n + cur;
cur++;
}
st.erase(st.begin());
}
return cur;
}
forn(1, i, n)
{
b[(i-start+n)%n+1] = a[i];
}
set <pii> st;
forn(1, i, n)
{
if(b[i] > n)
{
st.insert({b[i], i});
}
}
int cur = 0;
while(st.size())
{
replacementSeq[cur] = st.begin()->s;
cur++;
while(n + cur < st.begin()->f)
{
replacementSeq[cur] = n + cur;
cur++;
}
st.erase(st.begin());
}
return cur;
}
//----------------------
ll mod = 1e9+9;
ll binpow(ll a, ll n)
{
ll res = 1;
while(n)
{
if(n&1)
{
res = res * a % mod;
}
a = a * a % mod;
n /= 2;
}
return res;
}
int countReplacement(int n, int inputSeq[])
{
if(!valid(n, inputSeq))
{
return 0;
}
forn(1, i, n)
{
a[i] = inputSeq[i-1];
}
int start = 0;
forn(1, i, n)
{
if(a[i] <= n)
{
start = 1;
break;
}
}
vector <int> vec;
forn(1, i, n)
{
if(a[i] > n)
{
vec.pb(a[i]);
}
}
ll ans = 1;
int last = n;
sort(all(vec));
FOR(0, i, vec.size())
{
ans = ans * binpow((ll)(vec.size()) - i, vec[i] - last - 1);
last = vec[i];
}
if(!start) ans = ans * n % mod;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
3 | #pragma comment(linker, "/STACK:16777216")
|
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(j, i, n) for(int i = j; i < n; ++i)
......
175 | FOR(0, i, vec.size())
| ~~~~~~~~~~~~~
gondola.cpp:175:2: note: in expansion of macro 'FOR'
175 | FOR(0, i, vec.size())
| ^~~
# | 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... |