結果

問題 No.1013 〇マス進む
ユーザー saxofone111saxofone111
提出日時 2021-03-15 15:35:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 456 ms / 2,000 ms
コード長 4,377 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 209,688 KB
実行使用メモリ 33,024 KB
最終ジャッジ日時 2024-11-07 03:22:20
合計ジャッジ時間 16,050 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 3 ms
5,248 KB
testcase_07 AC 3 ms
5,248 KB
testcase_08 AC 3 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 4 ms
5,248 KB
testcase_13 AC 11 ms
5,248 KB
testcase_14 AC 145 ms
17,408 KB
testcase_15 AC 268 ms
26,240 KB
testcase_16 AC 241 ms
24,192 KB
testcase_17 AC 124 ms
15,488 KB
testcase_18 AC 164 ms
18,432 KB
testcase_19 AC 89 ms
12,288 KB
testcase_20 AC 345 ms
31,360 KB
testcase_21 AC 115 ms
14,592 KB
testcase_22 AC 165 ms
18,944 KB
testcase_23 AC 46 ms
8,192 KB
testcase_24 AC 371 ms
32,384 KB
testcase_25 AC 345 ms
31,608 KB
testcase_26 AC 48 ms
8,320 KB
testcase_27 AC 102 ms
13,952 KB
testcase_28 AC 46 ms
8,320 KB
testcase_29 AC 337 ms
30,720 KB
testcase_30 AC 98 ms
12,800 KB
testcase_31 AC 197 ms
21,504 KB
testcase_32 AC 132 ms
16,768 KB
testcase_33 AC 146 ms
16,768 KB
testcase_34 AC 272 ms
24,832 KB
testcase_35 AC 264 ms
23,808 KB
testcase_36 AC 15 ms
5,248 KB
testcase_37 AC 13 ms
5,248 KB
testcase_38 AC 299 ms
27,136 KB
testcase_39 AC 86 ms
10,880 KB
testcase_40 AC 285 ms
24,832 KB
testcase_41 AC 55 ms
8,448 KB
testcase_42 AC 149 ms
16,256 KB
testcase_43 AC 90 ms
11,648 KB
testcase_44 AC 155 ms
17,024 KB
testcase_45 AC 137 ms
15,360 KB
testcase_46 AC 61 ms
8,960 KB
testcase_47 AC 142 ms
16,256 KB
testcase_48 AC 177 ms
18,560 KB
testcase_49 AC 290 ms
24,704 KB
testcase_50 AC 218 ms
21,632 KB
testcase_51 AC 191 ms
19,712 KB
testcase_52 AC 35 ms
6,484 KB
testcase_53 AC 47 ms
8,064 KB
testcase_54 AC 220 ms
23,552 KB
testcase_55 AC 67 ms
9,216 KB
testcase_56 AC 346 ms
29,184 KB
testcase_57 AC 232 ms
20,864 KB
testcase_58 AC 456 ms
32,896 KB
testcase_59 AC 428 ms
32,896 KB
testcase_60 AC 373 ms
33,024 KB
testcase_61 AC 345 ms
32,980 KB
testcase_62 AC 308 ms
32,896 KB
testcase_63 AC 2 ms
5,248 KB
testcase_64 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

// @param b 1
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
std::pair<long long, long long> inv_gcd(long long a, long long b) {
  a = mod(a, b);
  if (a == 0) return {b, 0};

  // Contracts:
  // [1] s - m0 * a = 0 (mod b)
  // [2] t - m1 * a = 0 (mod b)
  // [3] s * |m1| + t * |m0| <= b
  long long s = b, t = a;
  long long m0 = 0, m1 = 1;

  while (t) {
    long long u = s / t;
    s -= t * u;
    m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b

    // [3]:
    // (s - t * u) * |m1| + t * |m0 - m1 * u|
    // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
    // = s * |m1| + t * |m0| <= b

    auto tmp = s;
    s = t;
    t = tmp;
    tmp = m0;
    m0 = m1;
    m1 = tmp;
  }
  // by [3]: |m0| <= b/g
  // by g != b: |m0| < b/g
  if (m0 < 0) m0 += b / s;
  return {s, m0};
}

// (rem, mod)
std::pair<long long, long long> crt(const std::vector<long long>& r,
                                    const std::vector<long long>& m) {
  assert(r.size() == m.size());
  int n = int(r.size());
  // Contracts: 0 <= r0 < m0
  long long r0 = 0, m0 = 1;
  for (int i = 0; i < n; i++) {
    assert(1 <= m[i]);
    long long r1 = mod(r[i], m[i]), m1 = m[i];
    if (m0 < m1) {
      std::swap(r0, r1);
      std::swap(m0, m1);
    }
    if (m0 % m1 == 0) {
      if (r0 % m1 != r1) return {0, 0};
      continue;
    }
    // assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)

    // (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
    // r2 % m0 = r0
    // r2 % m1 = r1
    // -> (r0 + x*m0) % m1 = r1
    // -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1)
    // -> x = (r1 - r0) / g * inv(u0) (mod u1)

    // im = inv(u0) (mod u1) (0 <= im < u1)
    long long g, im;
    std::tie(g, im) = inv_gcd(m0, m1);

    long long u1 = (m1 / g);
    // |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
    if ((r1 - r0) % g) return {0, 0};

    // u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
    long long x = (r1 - r0) / g % u1 * im % u1;

    // |r0| + |m0 * x|
    // < m0 + m0 * (u1 - 1)
    // = m0 + m0 * m1 / g - m0
    // = lcm(m0, m1)
    r0 += x * m0;
    m0 *= u1;  // -> lcm(m0, m1)
    if (r0 < 0) r0 += m0;
  }
  return {r0, m0};
}


bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

#define fracMax  10000000
ll frac[fracMax];
ll ifrac[fracMax];

void gen(){
  frac[0] = 1;
  ifrac[0] = 1;
  rep(i, fracMax-1){
    frac[i+1] = mod((i+1)*frac[i], MOD);
    ifrac[i+1] = modinv(frac[i+1], MOD);   
  }
  return;
}

ll binom(ll n, ll k){
  if(k<0 or k>n){
    return 0;
  }else{
    return mod(mod(frac[n]*ifrac[n-k], MOD)*ifrac[k], MOD);
  }
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K; 
  llvec a(N);
  rep(i, N){
    cin >> a[i];
  }
  vector<llvec> p(N, llvec(33, -1));
  rep(i, N){
    p[i][0] = a[i];
  }
  rep(k, 31){
    rep(i, N){
      p[i][k+1] = p[i][k] + p[mod(p[i][k] + i, N)][k];
    }
  }

  rep(i, N){
    ll k = K;
    ll cur = 0;
    rep(j, 32){
      if(k>>j&1){
        cur = cur + p[mod(cur + i, N)][j];
      }
    }
    cout << i+cur+1 <<endl;
  }
  
  return 0;
}
0