結果

問題 No.1013 〇マス進む
ユーザー T1610T1610
提出日時 2020-03-20 22:48:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 3,514 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 169,064 KB
実行使用メモリ 42,648 KB
最終ジャッジ日時 2023-08-21 17:55:10
合計ジャッジ時間 11,052 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 70 ms
21,716 KB
testcase_15 AC 152 ms
33,644 KB
testcase_16 AC 124 ms
31,048 KB
testcase_17 AC 61 ms
19,384 KB
testcase_18 AC 82 ms
23,024 KB
testcase_19 AC 43 ms
14,852 KB
testcase_20 AC 205 ms
40,724 KB
testcase_21 AC 53 ms
18,028 KB
testcase_22 AC 90 ms
23,868 KB
testcase_23 AC 21 ms
9,572 KB
testcase_24 AC 208 ms
41,888 KB
testcase_25 AC 187 ms
40,724 KB
testcase_26 AC 22 ms
9,972 KB
testcase_27 AC 50 ms
17,216 KB
testcase_28 AC 21 ms
9,944 KB
testcase_29 AC 186 ms
39,656 KB
testcase_30 AC 46 ms
15,716 KB
testcase_31 AC 106 ms
27,252 KB
testcase_32 AC 68 ms
20,912 KB
testcase_33 AC 72 ms
20,964 KB
testcase_34 AC 133 ms
31,736 KB
testcase_35 AC 143 ms
30,200 KB
testcase_36 AC 7 ms
4,860 KB
testcase_37 AC 6 ms
4,808 KB
testcase_38 AC 162 ms
34,708 KB
testcase_39 AC 40 ms
13,308 KB
testcase_40 AC 169 ms
31,788 KB
testcase_41 AC 26 ms
9,924 KB
testcase_42 AC 67 ms
20,660 KB
testcase_43 AC 43 ms
14,088 KB
testcase_44 AC 70 ms
21,284 KB
testcase_45 AC 58 ms
19,176 KB
testcase_46 AC 29 ms
10,744 KB
testcase_47 AC 65 ms
20,116 KB
testcase_48 AC 81 ms
23,352 KB
testcase_49 AC 150 ms
31,596 KB
testcase_50 AC 104 ms
27,296 KB
testcase_51 AC 99 ms
24,604 KB
testcase_52 AC 16 ms
7,196 KB
testcase_53 AC 22 ms
9,296 KB
testcase_54 AC 113 ms
30,208 KB
testcase_55 AC 30 ms
11,156 KB
testcase_56 AC 175 ms
37,332 KB
testcase_57 AC 116 ms
26,188 KB
testcase_58 AC 235 ms
42,616 KB
testcase_59 AC 210 ms
42,636 KB
testcase_60 AC 220 ms
42,648 KB
testcase_61 AC 208 ms
42,620 KB
testcase_62 AC 194 ms
42,296 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

namespace Doubling {
    using NODE_TYPE = int;
    using COST_TYPE = long long;
    // d[i][0]はあらかじめ計算しておく!
    void preCalc(vector<vector<NODE_TYPE>>& d, vector<vector<NODE_TYPE>>& over) {
        int n = d.size();
        int m = d[0].size();
        REP(j, 1, m) rep(i, n) {
            int cur = d[i][j-1];
            d[i][j] = d[d[i][j-1]][j-1];
            over[i][j] = over[i][j-1] + over[cur][j-1];
        }
        
    }
    // 頂点uからcostでいける頂点を求める
    ll getNode(NODE_TYPE u, COST_TYPE cost, const vector<vector<NODE_TYPE>>& d, vector<vector<NODE_TYPE>>& over) {
        int n = d.size();
        int m = d[0].size();
        NODE_TYPE cur = u;
        ll x = 0;
        repr(j, m) {
            if(cost&(COST_TYPE(1)<<j)) {
                x += over[cur][j];
                cur = d[cur][j];
                
            }
        }
        return cur + x * n;
    }
    // 頂点uから頂点vまでのコストを求める(iはトポロジカルソート後のidx)
    COST_TYPE getCost(NODE_TYPE u, NODE_TYPE v, const vector<vector<NODE_TYPE>>& d) {
        if(u >= v) assert(false);
        int n = d.size();
        int m = d[0].size();
        int cur = u;
        COST_TYPE ret = 0;
        while(cur < v) {
            if(d[cur][0] >= v) {
                ret += 1;
                break;
            }
            int j = lower_bound(all(d[cur]), v) - d[cur].begin() - 1;
            cur = d[cur][j];
            ret+= COST_TYPE(1) << j;
        }
        return ret;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vi p(n);
    rep(i, n) cin >> p[i];
    vector<vi> d(n, vi(40, -1));
    vector<vi> over(n, vi(40, -1));
    rep(i, n) {
        d[i][0] = (i+p[i]) %n;
        over[i][0] = (i >= d[i][0] ? 1 : 0);
        // dump(i);dump(d[i][0]);dumpL(over[i][0]);
    }
    Doubling::preCalc(d, over);
    rep(i, n) {
        cout << Doubling::getNode(i, k, d, over)+1 << '\n';
    }
    return 0;
}
0