結果

問題 No.1097 Remainder Operation
ユーザー hedwig100hedwig100
提出日時 2020-06-26 22:12:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,879 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 173,624 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-04 21:39:48
合計ジャッジ時間 5,403 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 221 ms
6,940 KB
testcase_18 AC 202 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:76:20: warning: 'size_of_loop' may be used uninitialized [-Wmaybe-uninitialized]
   76 |     ll before_loop,size_of_loop;
      |                    ^~~~~~~~~~~~
main.cpp:103:70: warning: 'before_loop' may be used uninitialized [-Wmaybe-uninitialized]
  103 |             ans += (ll)(K/size_of_loop) * Xs[Xsize] + Xs[before_loop + K%size_of_loop];
      |                                                          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
main.cpp:76:8: note: 'before_loop' was declared here
   76 |     ll before_loop,size_of_loop;
      |        ^~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct Debug {
    template<class T> static void print_value(T value,const char* name) {
        cout << name << ": " << value << '\n';
    }
    template<class T> static void print_vector(vector<T> &vec,const char* name) {
        for (int i = 0;i < vec.size();++i) {
            cout << "  " << name;
            printf("[%d]: ",i);
            cout << vec[i];
        }
        cout << '\n';
    }
    template<class T> static void print_2dvector(vector<vector<T>> &vec,const char* name) {
        for (int i = 0;i < vec.size();++i) {
            for (int j = 0;j < vec[i].size();++j) {
                cout << "  " << name;
                printf("[%d][%d]: ",i,j);
                cout << vec[i][j];
            }
            cout << '\n';
        }
    }
    template<class T> static void print_set(set<T> &st,const char* name) {
        int i = 0;
        for (auto itr = st.begin();itr != st.end(); ++itr,++i) {
            cout << "  " << name;
            printf("[%d]: ",i);
            cout << *itr;
        }
        cout << '\n';
    }

    template<class T1,class T2>
    static void print_map(map<T1,T2> &mp,const char* name) {
        for (auto p: mp) {
            cout << "  " << name << '[' << p.first << ']' << ": " << p.second;
        }
        cout << '\n';
    }
};

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    
    ll X = 0;
    vector<ll> Xs;
    Xs.push_back(0);
    vector<bool> remainder(N + 1,false);
    remainder[0] = true;
    
    X = A[X];
    while (!remainder[X%N]) {
        Xs.push_back(X);
        remainder[X%N] = true;
        X += A[X%N];
    }

    Xs.push_back(X);
    
    //Debug::print_vector(Xs,"Xs");

    ll before_loop,size_of_loop;
    for (int i = 0;i < Xs.size();++i) {
        if (Xs[i]%N == X%N) {
            before_loop = i;
            size_of_loop = Xs.size() - i - 1;
            break;
        }
    }
    if (before_loop > 0) {
        for (ll i = before_loop;i < Xs.size();++i) {
            Xs[i] -= Xs[before_loop - 1];
        }
    }
    //Debug::print_vector(Xs,"Xs");
    
    int Q; cin >> Q;
    int Xsize = Xs.size() - 1;
    rep(i,Q) {
        ll K; cin >> K;
        ll ans;
        if (K < before_loop) {
            ans = Xs[K];
        }
        else {
            ans = 0;
            if (before_loop) ans = Xs[before_loop - 1];
            K -= before_loop;
            ans += (ll)(K/size_of_loop) * Xs[Xsize] + Xs[before_loop + K%size_of_loop];
        }
        cout << ans << endl;
    }
    return 0;
}
0