結果
問題 | No.1013 〇マス進む |
ユーザー | jupiro |
提出日時 | 2020-03-20 22:21:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 147 ms / 2,000 ms |
コード長 | 1,849 bytes |
コンパイル時間 | 1,204 ms |
コンパイル使用メモリ | 118,120 KB |
実行使用メモリ | 67,552 KB |
最終ジャッジ日時 | 2024-12-15 06:35:48 |
合計ジャッジ時間 | 7,452 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N, K; scanf("%lld %lld", &N, &K); vector<ll> p(N); for (int i = 0; i < N; i++) scanf("%lld", &p[i]); vector<vector<ll>> t(40, vector<ll>(N)); vector<vector<ll>> t2(40, vector<ll>(N)); for (ll i = 0; i < N; i++) { t[0][i] = (i + p[i]) % N; if (i + p[i] >= N) { t2[0][i] = 1; //cout << i << endl; } } for (ll i = 0; i < 39; i++) { for (ll j = 0; j < N; j++) { t[i + 1][j] = t[i][t[i][j]]; t2[i + 1][j] = t2[i][t[i][j]] + t2[i][j]; } } for (ll start = 0; start < N; start++) { ll now = start; ll cnt = 0; for (ll i = 0; i < 40; i++) { if ((K >> i) & 1) { cnt += t2[i][now]; now = t[i][now]; } } printf("%lld\n", now + cnt * N + 1); } return 0; }