Submission #00098


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
long long int n,x[1000],p[1000];
set<int> w;
int dfs1(int now);
int dfs2(int now);
int main(){
long long int i;
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld %lld",&x[i],&p[i]);
}
for(i=0;i<n;i++){
int ans=0;
if(i==0)ans=1;
if(i==n-1)ans=10;
if(i>0){
w.insert(i);
ans+=dfs1(i);
w.clear();
}
if(i<n-1){
w.insert(i);
ans+=dfs2(i)*10;
w.clear();
}
if(ans==0)printf("X");
if(ans==1)printf("L");
if(ans==10)printf("R");
if(ans==11)printf("O");
}
printf("\n");
return(0);
}
int dfs1(int now){
int i;
if(now==0)return(1);
for(i=0;i<n;i++){
if(abs((int)(x[now]-x[i]))<=p[now]&&w.find(i)==w.end()){
w.insert(i);
if(dfs1(i))return(1);
w.erase(i);
}
}
return(0);
}
int dfs2(int now){
int i;
if(now==n-1)return(1);
for(i=n-1;i>=0;i--){
if(abs((int)(x[i]-x[now]))<=p[now]&&w.find(i)==w.end()){
w.insert(i);
if(dfs2(i))return(1);
w.insert(i);
}
}
return(0);
}

ステータス

項目 データ
問題 0004 - 想起「貪欲だった六番目」
ユーザー名 ei1620
投稿日時 2017-12-22 15:54:42
言語 C++11
状態 Accepted
得点 250
ソースコード長 1127 Byte
最大実行時間 25 ms
最大メモリ使用量 740 KB

セット

セット 得点 Cases
1 ALL 250 / 250 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 20 ms 476 KB
1
Input02 AC 22 ms 700 KB
1
Input03 AC 18 ms 668 KB
1
Input04 AC 18 ms 508 KB
1
Input05 AC 20 ms 600 KB
1
Input06 AC 16 ms 560 KB
1
Input07 AC 17 ms 644 KB
1
Input08 AC 20 ms 480 KB
1
Input09 AC 14 ms 448 KB
1
Input10 AC 14 ms 540 KB
1
Input11 AC 20 ms 632 KB
1
Input12 AC 16 ms 588 KB
1
Input13 AC 17 ms 548 KB
1
Input14 AC 15 ms 508 KB
1
Input15 AC 19 ms 592 KB
1
Input16 AC 23 ms 424 KB
1
Input17 AC 16 ms 508 KB
1
Input18 AC 21 ms 464 KB
1
Input19 AC 22 ms 428 KB
1
Input20 AC 22 ms 520 KB
1
Input21 AC 25 ms 476 KB
1
Input22 AC 21 ms 560 KB
1
Input23 AC 25 ms 520 KB
1
Input24 AC 21 ms 732 KB
1
Input25 AC 21 ms 688 KB
1
Input26 AC 15 ms 652 KB
1
Input27 AC 18 ms 740 KB
1
Input28 AC 18 ms 696 KB
1
Input29 AC 23 ms 524 KB
1
Input30 AC 15 ms 480 KB
1