이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N;
int T;
int reach[400100][30];
deque<int> dq;
int s,e;
vector<pair<int,int>> process;
vector<int> de;
int ans[400100];
int temp[400100];
int big(int j, int o, int n){
return (max( (o - j + T) % T, (n - j + T) % T) + j) % T;
}
int main(){
scanf(" %d",&N);
scanf(" %d",&T);
de.clear();
for(int i = 0; i < N; i++){
scanf(" %d",&s);
scanf(" %d",&e);
process.push_back({s,e});
de.push_back(s);
de.push_back(e);
}
sort(de.begin(),de.end());
de.resize(unique(de.begin(),de.end() ) - de.begin() );
for(int i = 0; i < de.size(); i++){
reach[i][0] = i;
}
T = de.size();
for(int i = 0; i < N; i++){
process[i].first = lower_bound(de.begin(), de.end(), process[i].first) - de.begin();
process[i].second = lower_bound(de.begin(), de.end(), process[i].second) - de.begin();
int j = process[i].first;
int p = process[i].second;
reach[j][0] = (max( (reach[j][0] - j + T) % T, (p - j + T) % T) + j) % T;
if(reach[(j - 1 + T) % T][0] != (j - 1 + T) % T)reach[j][0] = big(j,reach[j][0],reach[(j - 1 + T) % T ][0]);
}
for(int j = 0; j < T; j++){
if(reach[(j - 1 + T) % T][0] != (j - 1 + T) % T) reach[j][0] = big(j,reach[j][0],reach[(j - 1 + T) % T ][0]);
}
int cont = 1;
while(true){
if(cont == 29) break;
bool die = false;
for(int i = 0; i < T; i++){
reach[i][cont] = reach[reach[i][cont - 1]][cont - 1];
if(big(i,reach[i][cont], reach[i][cont - 1]) == reach[i][cont - 1] && reach[i][cont] != reach[i][cont - 1] ){
die = true;
break;
}
}
if(die) break;
cont++;
}
if(cont == 29){
printf("-1");
return 0;
}
int num = (1<<(cont - 1));
for(int i = 0; i < T; i++){
ans[i] = reach[i][cont - 1];
}
for(int k = cont - 1; k >= 0; k--){
bool die = false;
for(int i = 0; i < T; i++){
temp[i] = reach[ans[i]][k];
if(big(i, temp[i], ans[i]) == ans[i] && temp[i] != ans[i]){
die = true;
break;
}
}
if(die) continue;
num += (1<<k);
for(int i = 0; i < T; i++){
ans[i] = temp[i];
}
}
num++;
printf("%d",num);
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i = 0; i < de.size(); i++){
| ~~^~~~~~~~~~~
Main.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf(" %d",&T);
| ~~~~~^~~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf(" %d",&s);
| ~~~~~^~~~~~~~~~
Main.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf(" %d",&e);
| ~~~~~^~~~~~~~~~
# | 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... |