結果
| 問題 | No.1013 〇マス進む |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-03-23 19:08:30 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 182 ms / 2,000 ms |
| コード長 | 957 bytes |
| 記録 | |
| コンパイル時間 | 1,479 ms |
| コンパイル使用メモリ | 148,608 KB |
| 実行使用メモリ | 29,440 KB |
| 最終ジャッジ日時 | 2026-04-06 17:40:35 |
| 合計ジャッジ時間 | 8,679 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 62 |
コンパイルメッセージ
main.cpp:19:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
19 | ll P[N];
| ^
main.cpp:19:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
17 | int N, K;
| ^
main.cpp:24:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
24 | ll D[N][32];
| ^
main.cpp:24:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
17 | int N, K;
| ^
2 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, K;
cin >> N >> K;
ll P[N];
for (int i = 0; i < N; ++i) {
cin >> P[i];
}
ll D[N][32];
memset(D, 0, sizeof(D));
for (int step = 0; step < 32; ++step) {
for (int i = 0; i < N; ++i) {
if (step == 0) {
D[i][step] = (i + 1) + P[i];
} else {
int idx = (D[i][step - 1] - 1) % N;
D[i][step] = D[i][step - 1] + (D[idx][step - 1] - idx - 1);
}
}
}
for (int i = 0; i < N; ++i) {
int cur = i;
ll res = i + 1;
for (int step = 0; step < 30; ++step) {
if (K >> step & 1) {
res += (D[cur][step] - (cur + 1));
cur = (D[cur][step] - 1) % N;
}
}
cout << res << endl;
}
return 0;
}
siman