結果

問題 No.1535 五七五
ユーザー Manuel1024Manuel1024
提出日時 2021-06-06 18:33:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 72,620 KB
実行使用メモリ 24,528 KB
最終ジャッジ日時 2023-08-15 00:45:26
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 197 ms
24,400 KB
testcase_05 AC 255 ms
24,464 KB
testcase_06 AC 281 ms
24,456 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 162 ms
24,464 KB
testcase_19 AC 158 ms
24,388 KB
testcase_20 AC 161 ms
24,528 KB
testcase_21 AC 162 ms
24,328 KB
testcase_22 AC 163 ms
24,468 KB
testcase_23 AC 163 ms
24,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a, b, c;
    cin >> a >> b >> c;
    vector<string> s(n);
    for(auto &p: s) cin >> p;
    vector<int> lens(n);
    for(int i = 0; i < n; i++) lens[i] = s[i].length();
    
    vector<long long int> sum(n+1);
    for(int i = 0; i < n; i++){
        sum[i+1] = sum[i]+lens[i];
        //cerr << sum[i+1] << " ";
    }

    int ans = 0;
    for(int l = 0; l < n; l++){
        int l1 = l;
        int wa = n+1;
        while(wa-l1 > 1){
            int wj = (wa+l1)/2;
            if(sum[wj]-sum[l] <= a) l1 = wj;
            else wa = wj;
        }
        if(sum[l1]-sum[l] != a) continue;

        int l2 = l1;
        wa = n+1;
        while(wa-l2 > 1){
            int wj = (wa+l2)/2;
            if(sum[wj]-sum[l1] <= b) l2 = wj;
            else wa = wj;
        }

        if(sum[l2]-sum[l1] != b) continue;

        int r = l2;
        wa = n+1;
        while(wa-r > 1){
            int wj = (wa+r)/2;
            if(sum[wj]-sum[l2] <= c) r = wj;
            else wa = wj;
        }
        
        if(sum[r]-sum[l2] == c) ans++;
    }

    cout << ans << endl;

    return 0;
}
0