結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー ぷらぷら
提出日時 2024-02-23 21:45:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,742 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 140,200 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 21:45:30
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 129 ms
6,676 KB
testcase_02 AC 130 ms
6,676 KB
testcase_03 AC 130 ms
6,676 KB
testcase_04 AC 129 ms
6,676 KB
testcase_05 AC 243 ms
6,676 KB
testcase_06 AC 243 ms
6,676 KB
testcase_07 AC 14 ms
6,676 KB
testcase_08 AC 14 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 19 ms
6,676 KB
testcase_14 AC 19 ms
6,676 KB
testcase_15 AC 18 ms
6,676 KB
testcase_16 AC 19 ms
6,676 KB
testcase_17 AC 19 ms
6,676 KB
testcase_18 AC 18 ms
6,676 KB
testcase_19 AC 18 ms
6,676 KB
testcase_20 AC 19 ms
6,676 KB
testcase_21 AC 19 ms
6,676 KB
testcase_22 AC 19 ms
6,676 KB
testcase_23 AC 19 ms
6,676 KB
testcase_24 AC 19 ms
6,676 KB
testcase_25 AC 19 ms
6,676 KB
testcase_26 AC 19 ms
6,676 KB
testcase_27 AC 19 ms
6,676 KB
testcase_28 AC 19 ms
6,676 KB
testcase_29 AC 19 ms
6,676 KB
testcase_30 AC 19 ms
6,676 KB
testcase_31 AC 20 ms
6,676 KB
testcase_32 AC 19 ms
6,676 KB
testcase_33 AC 19 ms
6,676 KB
testcase_34 AC 102 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--) {
        string s;
        int m;
        cin >> s >> m;
        auto calc = [&](string a) {
            int ans = 0;
            for(int i = 0; i < a.size(); i++) {
                ans = (10ll*ans+(a[i]-'0'))%m;
            }
            return ans;
        };
        string t = s;
        if(t == string(t.size(),'9')) {
            t = "1"+string(t.size(),'0');
        }
        else {
            for(int i = t.size()-1; i >= 0; i--) {
                if(t[i] != '9') {
                    t[i] = (char)(t[i]+1);
                    for(int j = i+1; j < t.size(); j++) {
                        t[j] = '0';
                    }
                    break;
                }
            }
        }
        if((s.back()-'0')%2 == 0) {
            swap(s,t);
        }
        string r = "";
        for(int i = 0; i < t.size(); i++) {
            if(i == 0) {
                r += (char)('0'+(t[i]-'0')/2);
            }
            else {
                r += (char)('0'+((t[i-1]-'0')%2*10+t[i]-'0')/2);
            }
        }
        cout << 1ll*calc(s)*calc(r)%m << "\n";
    }
}
0