提出 #44294528


ソースコード 拡げる

#ifdef ONPC
#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("O3")
#pragma unroll
#endif

#include <bits/stdc++.h>

const int mod = 998244353;

int mult(int a, int b) {
    return (1ll * a * b) % mod;
}

int sum(int a, int b) {
    return (a + b) % mod;
}


using namespace std;

typedef long double ld;
typedef long long ll;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::cout << setprecision(15) << fixed;
#ifdef ONPC
    freopen("../input.txt", "r", stdin);
#endif
    int n;
    string s;
    vector<int> a = {0}, b;
    cin >> n >> s;
    if (s[0] != '1' && s[1] != '1') {
        cout << "-1";
        return 0;
    }
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1' || i == 0) {
            a.back()++;
        } else {
            b.push_back(s[i] - '1');
            if (a.back() == 0) {
                cout << "-1";
                return 0;
            }
            a.push_back(0);
        }
    }
    if (a.size() == 1) {
        cout << a.back() - 1 << '\n';
        return 0;
    }
    int cur = a.back() + 1;
//    cout << cur << "\n";
    a.pop_back();
    for (int i = a.size() - 1; i >= 0; --i) {
//        ll prev = cur;
        cur = sum(cur, sum(a[i] + 1, mult(cur, b[i])));
//        cout << cur << "\n";
    }
    cout << cur - 2 << "\n";
    return 0;
}

提出情報

提出日時
問題 E - Duplicate
ユーザ Paliukh
言語 C++ (GCC 9.2.1)
得点 600
コード長 1430 Byte
結果 AC
実行時間 24 ms
メモリ 9080 KiB

コンパイルエラー

./Main.cpp:5: warning: ignoring #pragma unroll  [-Wunknown-pragmas]
    5 | #pragma unroll
      | 

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 32
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 03_alternative_00.txt, 03_alternative_01.txt, 03_alternative_02.txt, 03_alternative_03.txt, 04_consecutive_1_00.txt, 04_consecutive_1_01.txt, 04_consecutive_1_02.txt, 04_consecutive_1_03.txt, 04_consecutive_1_04.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 4 ms 3572 KiB
00_sample_01.txt AC 2 ms 3552 KiB
00_sample_02.txt AC 3 ms 3592 KiB
01_small_00.txt AC 2 ms 3432 KiB
01_small_01.txt AC 2 ms 3536 KiB
01_small_02.txt AC 2 ms 3492 KiB
01_small_03.txt AC 4 ms 3480 KiB
01_small_04.txt AC 2 ms 3536 KiB
01_small_05.txt AC 4 ms 3436 KiB
02_random_00.txt AC 6 ms 4216 KiB
02_random_01.txt AC 18 ms 8592 KiB
02_random_02.txt AC 15 ms 7516 KiB
02_random_03.txt AC 6 ms 4172 KiB
02_random_04.txt AC 19 ms 7620 KiB
02_random_05.txt AC 24 ms 8792 KiB
02_random_06.txt AC 5 ms 4200 KiB
02_random_07.txt AC 21 ms 8816 KiB
02_random_08.txt AC 17 ms 8088 KiB
02_random_09.txt AC 6 ms 4200 KiB
02_random_10.txt AC 15 ms 7684 KiB
02_random_11.txt AC 21 ms 8748 KiB
02_random_12.txt AC 7 ms 4168 KiB
02_random_13.txt AC 24 ms 8704 KiB
03_alternative_00.txt AC 23 ms 8968 KiB
03_alternative_01.txt AC 19 ms 8968 KiB
03_alternative_02.txt AC 19 ms 9080 KiB
03_alternative_03.txt AC 23 ms 8980 KiB
04_consecutive_1_00.txt AC 7 ms 4088 KiB
04_consecutive_1_01.txt AC 7 ms 4144 KiB
04_consecutive_1_02.txt AC 14 ms 4220 KiB
04_consecutive_1_03.txt AC 10 ms 4172 KiB
04_consecutive_1_04.txt AC 8 ms 4128 KiB