結果

問題 No.1926 Sequence of Remainders
ユーザー da_ha_da_ha_
提出日時 2022-05-06 21:58:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 2,016 bytes
コンパイル時間 4,100 ms
コンパイル使用メモリ 260,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 02:51:37
合計ジャッジ時間 15,715 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 184 ms
4,376 KB
testcase_02 AC 183 ms
4,380 KB
testcase_03 AC 184 ms
4,376 KB
testcase_04 AC 187 ms
4,376 KB
testcase_05 AC 189 ms
4,380 KB
testcase_06 AC 253 ms
4,380 KB
testcase_07 AC 251 ms
4,376 KB
testcase_08 AC 252 ms
4,376 KB
testcase_09 AC 251 ms
4,380 KB
testcase_10 AC 251 ms
4,376 KB
testcase_11 AC 252 ms
4,380 KB
testcase_12 AC 250 ms
4,376 KB
testcase_13 AC 254 ms
4,376 KB
testcase_14 AC 253 ms
4,376 KB
testcase_15 AC 253 ms
4,380 KB
testcase_16 AC 248 ms
4,376 KB
testcase_17 AC 250 ms
4,380 KB
testcase_18 AC 250 ms
4,376 KB
testcase_19 AC 253 ms
4,376 KB
testcase_20 AC 247 ms
4,376 KB
testcase_21 AC 251 ms
4,376 KB
testcase_22 AC 252 ms
4,380 KB
testcase_23 AC 249 ms
4,380 KB
testcase_24 AC 252 ms
4,376 KB
testcase_25 AC 251 ms
4,380 KB
testcase_26 AC 256 ms
4,380 KB
testcase_27 AC 251 ms
4,380 KB
testcase_28 AC 257 ms
4,380 KB
testcase_29 AC 255 ms
4,376 KB
testcase_30 AC 254 ms
4,376 KB
testcase_31 AC 255 ms
4,380 KB
testcase_32 AC 251 ms
4,376 KB
testcase_33 AC 257 ms
4,376 KB
testcase_34 AC 254 ms
4,380 KB
testcase_35 AC 256 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef tuple<ll, ll, ll> Tll;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const double PI = 3.14159265358979323846;
int ddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int ddy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

void cans(bool f) {
    if (f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

template <typename T>
T gcd(T a, T b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

bool compare1(pair<ll, ll> a, pair<ll, ll> b) { return a.first < b.first; }
bool compare2(pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; }

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

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

ll facto(ll N) {
    if (N == 0) return 1;
    return facto(N - 1) * N;
}

ll dfs(ll val, ll div, ll cnt) {
    // cout << val << " " << div << " " << cnt << endl;
    if (val < div) {
        cnt -= (div - val);
        if (cnt >= 0) {
            val = div;
        }
    }
    if (val == 0) {
        return 0;
    }
    if (cnt < 0) {
        return val;
    }
    return dfs(val % div, div - 1, cnt - 1);
}

int main() {
    ll T;
    cin >> T;
    while (T--) {
        ll N, M, K;
        cin >> N >> M >> K;
        cout << dfs(K, M, N) << endl;
    }
}
0