結果

問題 No.2302 Carry X Times
ユーザー ococonomy1ococonomy1
提出日時 2023-05-12 23:18:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,370 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 110,544 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-06 13:19:05
合計ジャッジ時間 2,276 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
5,376 KB
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 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
using namespace std;
using lg = unsigned long long;
#define TEST clog << "TEST" << endl
#define IINF 2147483647
#define LLINF 9223372036854775807LL
//#define AMARI 1000000007
#define AMARI 998244353
#define TEMOTO ((sizeof(long double) == 16) ? false : true)
#define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000)
#define el '\n'
#define El '\n'

#define MULTI_TEST_CASE true
void solve(void) {
    lg n;
    int x;
    cin >> n >> x;
    vector<int> v(18, 0);
    for (int i = 0; i < x; i++)v[17 - i] = 1;
    lg ans = 0;
    do {
        lg temp = 1,zyuu = 10;
        for (int i = 0; i < 18; i++) {
            if (v[i]) {
                //この桁で繰り上がるのが何通りあるか求める
                lg zyougen = min(n, zyuu);
                lg x = zyougen - zyuu / 2; x %= AMARI; x--;
                if (zyougen <= zyuu / 2) {
                    temp = 0;
                    break;
                } 
                //if(v[0])clog << (x % AMARI);
                temp *= (((x + 1) * (2 * x + 1)) % AMARI);
                temp %= AMARI;
            }
            else {
                lg zyougen = min(n, zyuu);
                if (zyougen < zyuu / 2)continue;
                lg x = zyougen - zyuu / 2; x %= AMARI;
                temp *= (((zyougen % AMARI) * (zyougen % AMARI)) % AMARI) - (((x + 1) * (2 * x + 1)) % AMARI);
                //この桁で繰り上がらないのが何通りあるか求める
            }
            zyuu *= 10uLL;
        }
        ans += temp;
        ans %= AMARI;
        //clog << ans << el;
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << el;
    return;
}

void calc(void) {
    vector<int> v = { 0,0,0,1,1 };
    do {
        for (int i = 0; i < 5; i++) {
            cout << v[i];
        }
        cout << el;
    } while (next_permutation(v.begin(), v.end()));
    return;
}

int main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    if (MULTI_TEST_CASE)cin >> t;

    while (t--) {
        solve();
    }
    //calc();
    return 0;
}
0