# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
186612 | Ruxandra985 | Alternating Current (BOI18_alternating) | C++14 | 3022 ms | 1976 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;
pair <int,int> v[DIMN];
int d[DIMN] , cer[DIMN] , f[DIMN] , sol[DIMN];
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , m , i , j , ok , poz , what;
fscanf (fin,"%d%d",&n,&m);
for (i=1;i<=m;i++){
fscanf (fin,"%d%d",&v[i].first,&v[i].second);
if (v[i].first <= v[i].second){
for (j = v[i].first ; j <= v[i].second ; j++){
d[j]++;
}
}
else {
for (j = v[i].first ; j <= n ; j++){
d[j]++;
}
for (j = 1 ; j <= v[i].second ; j++){
d[j]++;
}
}
}
for (j=1;j<=m;j++){
ok = 0;
for (i=1;i<=n;i++){
if (d[i] == 1 && cer[i] < 3 && cer[i] > 0)
ok = i;
}
if (ok){
for (i=1;i<=m;i++){
if (!f[i]){ /// inca e relevant
if (v[i].first <= v[i].second && v[i].first <= ok && ok <= v[i].second){
poz = i;
f[i] = 1;
}
else if (v[i].first > v[i].second && (ok >= v[i].first || ok <= v[i].second)){
poz = i;
f[i] = 1;
}
}
}
what = cer[ok];
}
else {
what = 1;
for (i=1;i<=m;i++){
if (!f[i]){
poz = i;
f[i] = 1;
break;
}
}
}
sol[poz] = what - 1;
/// update
for (i=1;i<=n;i++){
if ((v[poz].first <= v[poz].second && v[poz].first <= i && i <= v[poz].second) ||
(v[poz].first > v[poz].second && (i >= v[poz].first || i <= v[poz].second))){
/// i e afectat de interval
d[i]--;
if (cer[i] == 0){
if (what == 1)
cer[i] = 2;
else cer[i] = 1;
}
else if (cer[i] == 3){}
else { /// e 1 sau 2 , cere ceva si i se da
if (cer[i] == what){
cer[i] = 3;
}
}
}
}
}
for (i=1;i<=n;i++){
if (cer[i] > 0 && cer[i] < 3){
fprintf (fout,"impossible");
return 0;
}
}
for (i=1;i<=m;i++){
fprintf (fout,"%d",sol[i]);
}
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... |