Submission #00291


ソースコード

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
#define S << " "
#define fin << "\n"
#define rn long double
#define SS << " " <<
#define nintendo switch
#define lol long long int
#define fout cout << "No\n"
#define tout cout << "Yes\n"
#define check cout << 1 fin;
#define ins(i) if(i) cout << " "
#define Iter(type) type::iterator
#define usort(a) sort(a.begin() , a.end())
#define dsort(a) sort(a.rbegin() , a.rend())
#define fixout(a) cout << fixed << setprecision(a)
#define push_pair(a , b) push_back(make_pair(a , b))
#define ub(a , b) upper_bound(a.begin() , a.end() , b)
#define lb(a , b) lower_bound(a.begin() , a.end() , b)
#define bs(a , b) binary_search(a.begin() , a.end() , b)
#define dptable(n , m) vvec(lol , dp , n + 1 , m + 1 , 0)
#define out_all(a , b) for(auto b = a.begin();b != a.end();b ++) cout << *b fin
#define vvec(type , arr , n , m , def) vector<vector<type>> arr(n , vector<type> (m , def))
using namespace std;
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
int n , m , p , q;
cin >> n >> m >> p >> q;
int ansx , ansy;
while(n && m && p && q){
ansx = -1;
ansy = -1;
p --;
q --;
vector<int> x(m);
for(int i = 0;i < m;i ++){
cin >> x[i];
x[i] --;
}
vector<vector<int>> mp(m + 1 , vector<int> (n));
mp[m][q] = 2;
int pos = q;
for(int i = m;0 < i;i --){
if(x[i - 1] == pos){
mp[i - 1][pos + 1] = 2;
pos ++;
}else if(x[i - 1] == pos - 1){
mp[i - 1][pos - 1] = 2;
pos --;
}else{
mp[i - 1][pos] = 2;
}
}
mp[0][p] = 1;
pos = p;
bool f = 1;
for(int i = 0;i <= m && f;i ++){
if(i != m){
if(x[i] == pos){
mp[i + 1][pos + 1] = 1;
pos ++;
}else if(x[i] == pos - 1){
mp[i + 1][pos - 1] = 1;
pos --;
}else{
mp[i + 1][pos] = 1;
}
}
if(f && (!i || (i != m && i && x[i - 1] != pos && x[i] != pos - 1))){
if(mp[i][pos + 1] == 2){
ansx = pos + 1;
ansy = i;
f = 0;
}
if(mp[i + 1][pos - 1] == 2){
ansx = pos + 1;
ansy = i - 1;
f = 0;
}
}
}
if(mp[m][q] == 1) cout << "OK\n";
else if(ansx == -1 && ansy == -1) cout << "NG\n";
else cout << ansx << " " << ansy fin;
// for(int i = 0;i <= m;i ++){
// for(int j = 0;j < n;j ++){
// cout << mp[i][j] << " ";
// }
// cout fin;
// }
cin >> n >> m >> p >> q;
}
return(0);
}

ステータス

項目 データ
問題 0007 - あみだくじ
ユーザー名 Koba_gochiusa
投稿日時 2024-03-29 15:01:15
言語 C++17
状態 Wrong Answer
得点 0
ソースコード長 3018 Byte
最大実行時間 35 ms
最大メモリ使用量 744 KB

セット

セット 得点 Cases
1 ALL 0 / 30 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
B1 WA 31 ms 604 KB
1
B2 WA 35 ms 568 KB
1
B3 WA 27 ms 656 KB
1
B4 WA 24 ms 744 KB
1