# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
633883 | lovrot | Nice sequence (IZhO18_sequence) | C++11 | 2069 ms | 2240 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
using namespace std;
const int N = 2 * 1e5 + 10;
int t, n, m, p[N], ans;
int pos;
int cyc[N], bio[N], ts[N], cookie;
bool cycp(int u){
bio[u] = cookie;
cyc[u] = cookie;
// cout << u << "\n";
int lv = u - m, uv = u + n;
if(lv >= 0){
if(cyc[lv] == cookie)
return true;
if(cycp(lv))
return true;
}
if(uv <= ans){
if(cyc[uv] == cookie)
return true;
if(cycp(uv))
return true;
}
cyc[u] = -cookie;
return false;
}
void topSort(int u){
ts[u] = cookie;
int lv = u - m, uv = u + n;
if(lv >= 0){
if(ts[lv] != cookie) topSort(lv);
}
if(uv <= ans){
if(ts[uv] != cookie) topSort(uv);
}
p[u] = ++pos;
}
void output(){
for(int i = 0; i <= ans; i++)
if(ts[i] != cookie) topSort(i);
printf("%d\n", ans);
for(int i = 1; i <= ans; i++)
printf("%d ", (p[i] - p[0]) - (p[i - 1] - p[0]));
printf("\n");
}
bool probaj(){
pos = -1;
cookie++;
for(int i = 0; i <= ans; i++){
if(bio[i] != cookie){
if(cycp(i))
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &m);
int lo = 0, hi = (n + m) + 1;
while(hi - lo > 1){
int mi = (lo + hi) / 2;
ans = mi;
if(probaj())
lo = mi;
else
hi = mi;
}
ans = lo;
probaj();
output();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |