Submission #60749313


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define int long long
#define pii pair<int,int>
void solve() {
int n,x;
cin >> n >> x;
int s = 0;
vector<int> a(n+9),pre(n+9,0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
s+=a[i];
pre[i] = pre[i-1] + a[i];
}
x%=s;
//cout << x << endl;
if (x == 0) {
cout << "Yes";
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define int long long
#define pii pair<int,int>

void solve() {
    int n,x;
    cin >> n >> x;
    int s = 0;
    vector<int> a(n+9),pre(n+9,0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s+=a[i];
        pre[i] = pre[i-1] + a[i];
    }
    x%=s;
    //cout << x << endl;
    if (x == 0) {
        cout << "Yes";
        return;
    }
    int t = 0;
    int j = 1;
    for (int i = 1; i <= n; i++) {
        t+=a[i];
        while (t > x) {
            t-=a[j];
            j = (j-1+1)%n+1;
        }
        if (t == x) {
            cout << "Yes";
            return;
        }
    }
    
    t = 0;
    j = n;
    for (int i = n; i >= 1; i--) {
        t+=a[i];
        while (t > x) {
            t-=a[j];
            j = (j-1-1)%n+1;
        }
        if (t == x) {
            cout << "Yes";
            return;
        }
    }

    t = x;
    for (int i = 1; i <= n; i++) {
        t-=a[i];
        if (t < 0) break;
        int l = 1;
        int r = n;
        while (l <= r) {
            int mid = (l+r)/2;
            if (pre[n]-pre[mid-1] == t) {
                cout << "Yes";
                return;
            }else if (pre[n] - pre[mid-1] < t) {
                r = mid-1;
            }else {
                l = mid+1;
            }
        }
    }

    t = x;
    for (int i = n; i >= 1; i--) {
        t-=a[i];
        if (t < 0) break;
        int l = 1;
        int r = n;
        while (l <= r) {
            int mid = (l+r)/2;
            if (pre[mid] == t) {
                cout << "Yes";
                return;
            }else if (pre[mid] > t) {
                r = mid-1;
            }else {
                l = mid+1;
            }
        }
    }

    cout << "No";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    t = 1;
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task D - Repeated Sequence
User CirnoNine
Language C++ 23 (gcc 12.2)
Score 400
Code Size 2078 Byte
Status AC
Exec Time 28 ms
Memory 6340 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 54
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 02_handmade_46.txt, 02_handmade_47.txt, 02_handmade_48.txt, 02_handmade_49.txt, 02_handmade_50.txt, 02_handmade_51.txt, 02_handmade_52.txt, 02_handmade_53.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3472 KB
00_sample_01.txt AC 1 ms 3396 KB
00_sample_02.txt AC 1 ms 3424 KB
00_sample_03.txt AC 1 ms 3424 KB
01_random_04.txt AC 12 ms 6204 KB
01_random_05.txt AC 21 ms 6340 KB
01_random_06.txt AC 12 ms 6236 KB
01_random_07.txt AC 27 ms 6336 KB
01_random_08.txt AC 13 ms 6180 KB
01_random_09.txt AC 20 ms 6164 KB
01_random_10.txt AC 17 ms 6236 KB
01_random_11.txt AC 17 ms 6248 KB
01_random_12.txt AC 12 ms 6204 KB
01_random_13.txt AC 13 ms 6268 KB
01_random_14.txt AC 13 ms 6316 KB
01_random_15.txt AC 23 ms 6320 KB
01_random_16.txt AC 12 ms 6168 KB
01_random_17.txt AC 17 ms 6240 KB
01_random_18.txt AC 12 ms 6160 KB
01_random_19.txt AC 17 ms 6228 KB
01_random_20.txt AC 22 ms 6164 KB
01_random_21.txt AC 13 ms 6248 KB
01_random_22.txt AC 27 ms 6164 KB
01_random_23.txt AC 18 ms 6172 KB
01_random_24.txt AC 28 ms 6248 KB
01_random_25.txt AC 12 ms 6156 KB
01_random_26.txt AC 14 ms 6240 KB
01_random_27.txt AC 11 ms 6332 KB
01_random_28.txt AC 7 ms 5016 KB
01_random_29.txt AC 1 ms 3560 KB
01_random_30.txt AC 2 ms 3612 KB
01_random_31.txt AC 6 ms 4308 KB
01_random_32.txt AC 18 ms 5392 KB
01_random_33.txt AC 1 ms 3576 KB
01_random_34.txt AC 5 ms 4252 KB
01_random_35.txt AC 5 ms 3844 KB
01_random_36.txt AC 3 ms 3628 KB
01_random_37.txt AC 10 ms 5208 KB
01_random_38.txt AC 10 ms 4044 KB
01_random_39.txt AC 3 ms 3496 KB
01_random_40.txt AC 21 ms 6244 KB
01_random_41.txt AC 12 ms 6156 KB
01_random_42.txt AC 12 ms 6248 KB
01_random_43.txt AC 5 ms 3844 KB
01_random_44.txt AC 11 ms 4396 KB
01_random_45.txt AC 2 ms 3624 KB
02_handmade_46.txt AC 7 ms 6168 KB
02_handmade_47.txt AC 1 ms 3428 KB
02_handmade_48.txt AC 7 ms 6244 KB
02_handmade_49.txt AC 1 ms 3404 KB
02_handmade_50.txt AC 17 ms 6240 KB
02_handmade_51.txt AC 12 ms 6336 KB
02_handmade_52.txt AC 10 ms 6240 KB
02_handmade_53.txt AC 9 ms 6180 KB


2025-03-14 (Fri)
16:42:33 +00:00