Submission #58388
ソースコード
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 | #include <iostream> #include <queue> #include <tuple> using namespace std; const int tenkey[4][3] = { {7,8,9}, {4,5,6}, {1,2,3}, {0,-1,-1} }; const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1}; const int INF = 1e9; inline bool isKeyExist( int x, int y){ return x >= 0 && x < 4 && y >= 0 && y < 3 && tenkey[x][y] != -1; } signed main(){ int m,r; cin >> m >> r; int dist[100010][4][3] = {}; for ( int i = 0;i < m;i++){ for ( int j = 0;j < 4;j++){ for ( int k = 0;k < 3;k++) dist[i][j][k] = INF; } } queue<tuple< int , int , int >> que; que.emplace(0,3,0); dist[0][3][0] = 0; while (!que.empty()){ int rem,x,y; tie(rem,x,y) = que.front(); que.pop(); int newrem = (rem * 10 + tenkey[x][y]) % m; if (dist[newrem][x][y] == INF){ dist[newrem][x][y] = dist[rem][x][y] + 1; que.emplace(newrem,x,y); } for ( int j = 0;j < 4;j++){ int nx = x + dx[j],ny = y + dy[j]; if (isKeyExist(nx,ny) && dist[rem][nx][ny] == INF){ dist[rem][nx][ny] = dist[rem][x][y] + 1; que.emplace(rem,nx,ny); } } } int ans = INF; for ( int i = 0;i < 4;i++){ for ( int j = 0;j < 3;j++) ans = min(ans,dist[r][i][j]); } cout << ans << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 1268 - テンキー (Tenkey) |
ユーザー名 | syoribu |
投稿日時 | 2020-02-03 15:54:43 |
言語 | C++14 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1397 Byte |
最大実行時間 | 64 ms |
最大メモリ使用量 | 9448 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | Subtask1 | 30 / 30 | sample*, 01* |
2 | Subtask2 | 70 / 70 | sample*, 01*, 02* |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | |
---|---|---|---|---|---|
01-01.txt | AC | 47 ms | 6748 KB |
1
|
2
|
01-02.txt | AC | 50 ms | 6760 KB |
1
|
2
|
01-03.txt | AC | 50 ms | 6724 KB |
1
|
2
|
01-04.txt | AC | 48 ms | 6648 KB |
1
|
2
|
01-05.txt | AC | 40 ms | 6736 KB |
1
|
2
|
01-06.txt | AC | 53 ms | 6660 KB |
1
|
2
|
01-07.txt | AC | 49 ms | 6676 KB |
1
|
2
|
01-08.txt | AC | 50 ms | 6684 KB |
1
|
2
|
01-09.txt | AC | 44 ms | 6564 KB |
1
|
2
|
01-10.txt | AC | 49 ms | 6704 KB |
1
|
2
|
01-11.txt | AC | 44 ms | 6720 KB |
1
|
2
|
01-12.txt | AC | 46 ms | 6816 KB |
1
|
2
|
01-13.txt | AC | 47 ms | 6828 KB |
1
|
2
|
01-14.txt | AC | 57 ms | 6880 KB |
1
|
2
|
02-01.txt | AC | 17 ms | 5224 KB |
2
|
|
02-02.txt | AC | 20 ms | 5368 KB |
2
|
|
02-03.txt | AC | 25 ms | 5348 KB |
2
|
|
02-04.txt | AC | 30 ms | 5236 KB |
2
|
|
02-05.txt | AC | 24 ms | 5232 KB |
2
|
|
02-06.txt | AC | 23 ms | 5240 KB |
2
|
|
02-07.txt | AC | 53 ms | 7420 KB |
2
|
|
02-08.txt | AC | 39 ms | 7708 KB |
2
|
|
02-09.txt | AC | 49 ms | 8444 KB |
2
|
|
02-10.txt | AC | 50 ms | 8040 KB |
2
|
|
02-11.txt | AC | 34 ms | 6616 KB |
2
|
|
02-12.txt | AC | 24 ms | 5968 KB |
2
|
|
02-13.txt | AC | 58 ms | 8872 KB |
2
|
|
02-14.txt | AC | 56 ms | 8728 KB |
2
|
|
02-15.txt | AC | 24 ms | 5644 KB |
2
|
|
02-16.txt | AC | 57 ms | 9132 KB |
2
|
|
02-17.txt | AC | 30 ms | 6412 KB |
2
|
|
02-18.txt | AC | 39 ms | 7092 KB |
2
|
|
02-19.txt | AC | 60 ms | 9180 KB |
2
|
|
02-20.txt | AC | 57 ms | 8744 KB |
2
|
|
02-21.txt | AC | 64 ms | 9040 KB |
2
|
|
02-22.txt | AC | 28 ms | 5336 KB |
2
|
|
02-23.txt | AC | 23 ms | 5212 KB |
2
|
|
02-24.txt | AC | 58 ms | 9172 KB |
2
|
|
02-25.txt | AC | 62 ms | 9312 KB |
2
|
|
02-26.txt | AC | 62 ms | 9252 KB |
2
|
|
02-27.txt | AC | 53 ms | 8856 KB |
2
|
|
02-28.txt | AC | 61 ms | 9248 KB |
2
|
|
02-29.txt | AC | 59 ms | 9448 KB |
2
|
|
02-30.txt | AC | 56 ms | 9264 KB |
2
|
|
02-31.txt | AC | 51 ms | 7968 KB |
2
|
|
02-32.txt | AC | 53 ms | 9244 KB |
2
|
|
02-33.txt | AC | 44 ms | 7200 KB |
2
|
|
02-34.txt | AC | 42 ms | 7296 KB |
2
|
|
02-35.txt | AC | 48 ms | 7312 KB |
2
|
|
sample-01.txt | AC | 51 ms | 6996 KB |
1
|
2
|
sample-02.txt | AC | 26 ms | 5468 KB |
1
|
2
|