Submission #1372998


Source Code Expand

/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7, MAXN = 1e5 + 10;

int n, a[MAXN], id;

pii rec(int i){
    int ans, mn = INF, cnt = 0, mni;
    for (int j = 0; j < n; ++j){
        a[(i + j) % n] -= j + 1;
        if (a[(i + j) % n] < 0)
            return {0, 0};
        if (a[(i + j) % n] < mn)
            mn = a[(i + j) % n], mni = (i + j) % n;
        if (a[(i + j) % n] == 0)
            ++cnt;
    }
    if (cnt == n)
        return {1, -1};
    return {2, mni};
}

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);

    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        if (a[i] < a[id])
            id = i;
    }
    while (true){
        pii p = rec(id);
//        if (id == 4){
//            for (int i = 0; i < n; ++i)
//                cout << a[i] << " ";
//            cout << "\n";
//        }
        if (p.fr == 1){
            cout << "YES";
            return 0;
        }
        if (p.fr == 0){
            cout << "NO";
            return 0;
        }
        id = p.sc;
    }

    return 0;
}

Submission Info

Submission Time
Task B - Boxes
User Sakzhan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1398 Byte
Status TLE
Exec Time 2103 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 21
TLE × 12
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 14 ms 640 KB
in10.txt AC 1756 ms 256 KB
in11.txt TLE 2103 ms 640 KB
in12.txt TLE 2103 ms 640 KB
in13.txt AC 596 ms 640 KB
in14.txt AC 1 ms 256 KB
in15.txt TLE 2103 ms 256 KB
in16.txt TLE 2103 ms 256 KB
in17.txt TLE 2103 ms 256 KB
in18.txt TLE 2103 ms 256 KB
in19.txt AC 1 ms 256 KB
in2.txt TLE 2103 ms 640 KB
in20.txt AC 1 ms 256 KB
in21.txt AC 12 ms 640 KB
in22.txt AC 12 ms 640 KB
in23.txt AC 11 ms 640 KB
in24.txt AC 401 ms 256 KB
in25.txt AC 1125 ms 256 KB
in26.txt AC 812 ms 640 KB
in27.txt AC 1812 ms 640 KB
in3.txt TLE 2103 ms 640 KB
in4.txt TLE 2103 ms 640 KB
in5.txt TLE 2103 ms 640 KB
in6.txt TLE 2103 ms 640 KB
in7.txt TLE 2103 ms 640 KB
in8.txt AC 391 ms 256 KB
in9.txt AC 1946 ms 256 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB