QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463896#2526. Imprecise Computeryzkkai#AC ✓38ms7108kbC++20843b2024-07-05 15:44:112024-07-05 15:44:12

Judging History

This is the latest submission verdict.

  • [2024-07-05 15:44:12]
  • Judged
  • Verdict: AC
  • Time: 38ms
  • Memory: 7108kb
  • [2024-07-05 15:44:11]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

inline void solve() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (int &i : a)
        cin >> i;
    
    for (int i = 0; i < n; ++i)
        if (a[i] < 0 || a[i] > 2) {
            cout << "NO\n";
            return;
        }

    bool ok = 1;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i] == 0) 
           continue;
        else if (a[i] == 1) {
            if (a[i + 1] == 0)
                a[i + 1] = 1;
            else
                a[i + 1] -= 1;

        }
        else {
            ok = 0;
            break;
        }
    }
    cout << (ok && a.back() == 0 ? "YES" : "NO") << '\n';
    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;

    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

10
1 2 3 3 3 3 2 1 2 2

output:

NO

result:

ok single line: 'NO'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

10
0 0 0 0 0 0 0 0 0 1

output:

NO

result:

ok single line: 'NO'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

10
0 1 0 1 0 1 0 1 0 1

output:

NO

result:

ok single line: 'NO'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

10
1 0 1 0 1 0 1 0 1 0

output:

NO

result:

ok single line: 'NO'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

10
1 2 2 2 2 2 2 2 0 1

output:

YES

result:

ok single line: 'YES'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

10
1 2 2 2 2 2 2 2 0 0

output:

NO

result:

ok single line: 'NO'

Test #7:

score: 0
Accepted
time: 38ms
memory: 7092kb

input:

1000000
0 1 2 1 0 1 2 1 0 1 1 1 0 0 1 0 1 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 0 1 2 0 0 1 1 2 2 0 2 0 2 1 1 0 2 2 0 0 2 1 0 0 0 1 0 2 1 1 1 0 1 0 1 1 1 0 1 1 1 2 1 0 0 0 1 0 1 0 0 1 0 1 1 0 1 1 0 2 2 1 1 0 2 0 2 2 1 1 1 0 1 2 1 0 1 0 1 0 0 1 1 0 0 1 2 0 2 1 1 1 0 1 0 1 0 0 0 0 0 1 2 1 1 0 0 1 0 1 ...

output:

NO

result:

ok single line: 'NO'

Test #8:

score: 0
Accepted
time: 34ms
memory: 6980kb

input:

1000000
1 0 0 0 2 0 2 2 1 1 0 2 0 0 0 1 0 1 1 1 2 2 2 2 1 0 0 1 2 1 1 0 0 0 2 0 0 0 2 2 2 1 1 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 0 2 1 1 1 0 0 0 1 2 2 0 0 0 0 2 2 2 1 1 0 0 1 0 1 1 1 0 2 1 1 0 2 1 1 1 1 1 0 0 0 1 2 1 1 1 1 1 0 1 2 2 0 2 1 1 0 2 0 0 1 1 2 2 2 0 1 1 2 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 2 ...

output:

NO

result:

ok single line: 'NO'

Test #9:

score: 0
Accepted
time: 38ms
memory: 7020kb

input:

1000000
1 2 0 0 0 1 1 1 0 1 2 2 2 0 0 1 0 1 2 1 0 0 0 0 0 1 1 1 0 1 0 1 1 1 2 0 1 0 1 1 1 0 2 2 2 1 0 1 1 1 2 2 0 0 0 0 0 0 2 0 0 1 0 0 1 2 0 2 0 1 0 0 1 1 0 1 1 0 1 0 2 2 0 1 0 0 0 0 0 1 1 1 0 2 0 2 2 0 1 1 0 1 0 1 1 0 0 1 0 0 0 2 2 2 1 0 1 2 1 1 0 0 2 0 1 1 2 2 2 1 1 0 2 1 0 1 1 0 1 1 0 0 1 0 2 0 ...

output:

YES

result:

ok single line: 'YES'

Test #10:

score: 0
Accepted
time: 37ms
memory: 7000kb

input:

1000000
0 0 0 0 0 1 2 2 2 1 1 1 0 1 0 2 1 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 2 0 2 2 2 0 0 0 0 0 2 0 1 0 1 0 2 0 0 2 2 2 0 1 0 1 0 0 0 2 0 0 1 0 0 1 1 1 0 1 1 0 2 1 1 2 1 1 1 1 2 1 1 0 0 1 0 1 2 2 1 0 0 0 0 1 0 1 1 0 2 1 1 2 1 1 1 0 0 1 2 2 1 1 1 1 0 2 2 2 2 1 1 2 1 0 0 1 1 1 2 1 1 2 1 0 0 0 0 0 0 0 1 ...

output:

NO

result:

ok single line: 'NO'

Test #11:

score: 0
Accepted
time: 34ms
memory: 6940kb

input:

1000000
1 1 1 0 2 2 2 0 0 1 0 0 0 1 0 1 0 1 0 1 1 2 0 2 2 0 0 1 1 0 2 1 0 1 0 1 0 1 0 2 2 0 1 0 1 0 2 1 0 0 0 0 1 1 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 2 0 1 0 0 1 0 1 1 1 1 0 1 0 1 2 0 2 1 0 1 0 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 0 1 0 2 1 1 0 1 0 1 1 0 1 1 0 1 0 0 1 0 1 2 2 2 2 1 1 2 0 ...

output:

YES

result:

ok single line: 'YES'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

10
2 1 1 1 1 1 1 1 1 1

output:

NO

result:

ok single line: 'NO'

Test #13:

score: 0
Accepted
time: 33ms
memory: 6940kb

input:

1000000
1 2 0 0 1 1 1 0 1 2 1 0 0 1 0 1 0 1 2 2 0 0 1 1 0 1 1 2 0 1 0 1 0 2 2 2 2 0 2 0 2 1 1 0 1 1 1 0 1 0 0 2 1 0 0 1 1 0 1 0 1 1 2 0 1 1 0 1 0 0 1 1 0 1 2 0 0 1 0 0 1 1 0 0 1 2 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 2 0 0 2 1 0 1 1 0 0 1 1 1 0 0 1 1 2 1 1 1 1 0 2 0 1 1 1 0 0 0 0 0 0 1 2 1 1 0 2 1 0 0 1 0 ...

output:

YES

result:

ok single line: 'YES'

Test #14:

score: 0
Accepted
time: 35ms
memory: 6968kb

input:

1000000
1 0 0 0 2 0 0 1 1 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 0 1 1 0 1 2 0 1 0 0 0 1 2 0 1 1 2 1 1 0 1 1 2 2 1 1 2 2 1 0 1 1 1 0 0 2 2 2 1 0 1 2 2 0 0 0 1 1 1 0 0 0 0 1 0 0 0 2 1 1 1 1 0 1 1 2 0 1 1 0 1 1 2 2 2 0 2 1 1 1 1 2 1 0 1 1 0 1 0 1 1 0 0 2 0 0 0 2 2 0 2 1 1 0 0 2 1 1 2 1 0 1 1 1 1 0 1 0 0 0 ...

output:

NO

result:

ok single line: 'NO'

Test #15:

score: 0
Accepted
time: 33ms
memory: 7036kb

input:

1000000
1 2 2 0 0 1 0 1 2 1 1 0 2 1 0 1 1 1 1 0 1 1 0 0 1 0 2 1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 2 0 1 0 1 2 1 1 0 0 0 1 1 2 0 1 1 2 1 0 1 0 0 2 1 0 1 1 1 1 1 2 0 0 2 1 1 2 1 1 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 2 0 0 0 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 1 1 2 0 1 0 0 0 1 1 1 0 0 2 1 0 0 1 0 0 ...

output:

NO

result:

ok single line: 'NO'

Test #16:

score: 0
Accepted
time: 34ms
memory: 7024kb

input:

1000000
1 0 2 0 1 1 2 0 1 0 0 1 0 2 0 1 0 1 2 2 1 1 0 2 1 1 2 0 1 1 0 1 1 2 0 2 1 0 0 1 1 1 0 1 0 0 0 0 0 0 1 0 2 2 0 0 2 0 2 1 0 1 0 0 2 0 1 0 1 0 2 0 1 1 1 0 1 1 1 1 0 1 0 0 0 2 1 0 1 1 0 0 1 0 0 2 0 1 1 0 0 1 0 0 0 1 2 2 2 2 2 0 0 2 0 0 0 0 2 0 0 0 0 1 0 1 0 1 0 1 1 0 1 2 2 0 1 0 0 0 0 0 1 0 0 0 ...

output:

YES

result:

ok single line: 'YES'

Test #17:

score: 0
Accepted
time: 34ms
memory: 7084kb

input:

1000000
1 2 1 0 0 1 2 0 1 0 1 0 2 0 0 1 0 1 1 0 1 2 2 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 2 1 0 1 0 2 0 2 0 2 2 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 1 2 2 2 0 1 0 0 0 1 0 0 0 1 1 2 0 1 0 1 0 2 0 2 0 0 1 0 1 1 0 0 1 0 2 0 1 0 0 1 2 2 1 1 1 0 1 1 1 2 1 0 1 1 1 2 0 2 1 0 1 2 2 1 1 1 1 2 0 2 0 1 1 0 1 0 0 1 0 0 ...

output:

NO

result:

ok single line: 'NO'

Test #18:

score: 0
Accepted
time: 34ms
memory: 7016kb

input:

1000000
1 1 1 0 0 2 2 2 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 1 2 0 1 0 0 1 2 0 0 1 1 0 0 0 1 1 1 0 0 1 0 2 0 1 0 0 1 2 0 1 1 1 0 1 1 0 0 1 0 2 0 2 0 1 0 1 1 0 1 0 2 0 2 0 2 1 0 1 2 2 1 0 1 0 0 0 2 2 0 0 0 0 1 1 1 1 1 1 0 0 0 2 0 0 0 2 2 2 1 1 0 0 1 1 2 0 0 0 0 0 2 1 1 1 1 2 2 0 1 1 2 2 2 0 1 0 1 2 0 0 ...

output:

NO

result:

ok single line: 'NO'

Test #19:

score: 0
Accepted
time: 31ms
memory: 7092kb

input:

1000000
1 2 2 1 1 1 0 0 1 2 1 0 0 1 2 0 1 1 0 2 1 0 1 2 2 2 1 1 1 0 0 0 1 0 0 0 0 1 1 2 2 2 2 0 2 1 1 0 0 1 0 1 2 2 1 1 1 1 2 2 0 1 0 0 0 1 2 1 0 1 1 1 1 0 0 0 1 0 2 1 0 1 2 1 0 0 0 1 1 1 1 1 1 0 0 0 1 2 2 1 0 1 1 0 0 1 2 0 1 1 2 2 1 0 0 0 0 0 0 0 1 0 2 0 0 1 0 0 0 0 0 1 2 1 0 0 0 0 1 1 0 1 1 1 1 0 ...

output:

NO

result:

ok single line: 'NO'

Test #20:

score: 0
Accepted
time: 34ms
memory: 7104kb

input:

1000000
1 1 1 1 0 1 0 1 1 2 0 1 1 2 2 2 1 1 1 1 0 0 2 1 1 1 1 1 0 0 0 0 1 2 2 0 1 1 1 0 1 1 1 2 2 2 1 0 1 2 0 2 0 1 0 1 0 1 0 0 1 2 2 0 2 1 0 0 0 1 2 1 0 1 0 0 0 0 2 1 1 2 2 2 2 0 0 1 1 1 1 2 2 0 1 1 1 1 0 0 0 0 2 0 0 1 0 1 0 0 1 1 1 0 0 1 2 2 1 1 1 1 2 1 1 0 1 0 0 1 2 2 0 2 0 0 1 0 1 0 0 2 1 0 0 1 ...

output:

NO

result:

ok single line: 'NO'

Test #21:

score: 0
Accepted
time: 34ms
memory: 6984kb

input:

1000000
1 0 1 1 0 2 0 1 0 0 1 1 1 0 2 2 2 0 2 2 2 1 0 1 0 0 0 0 1 1 1 1 0 1 1 2 2 2 2 1 1 0 0 0 2 2 1 0 0 0 1 2 2 2 0 1 1 0 1 0 1 0 1 1 1 1 1 0 0 1 0 2 1 1 2 2 2 0 1 1 1 0 0 1 2 0 1 1 0 0 0 0 2 1 0 1 2 2 0 2 2 2 2 1 0 1 0 0 2 2 0 1 0 1 1 1 1 1 0 2 1 0 1 2 1 1 0 0 2 1 1 0 2 0 1 1 0 0 0 2 0 0 1 0 0 1 ...

output:

NO

result:

ok single line: 'NO'

Test #22:

score: 0
Accepted
time: 31ms
memory: 7108kb

input:

1000000
1 2 1 0 0 0 0 0 1 2 2 1 1 1 1 2 0 2 0 1 1 2 0 2 0 2 0 1 0 0 0 1 1 1 1 0 1 2 0 0 0 2 0 2 1 1 1 1 1 1 2 2 0 0 2 2 1 1 2 2 1 0 1 0 0 0 0 0 1 1 1 1 2 0 1 0 1 0 1 0 1 0 2 0 1 1 0 0 1 0 0 1 2 2 2 2 0 0 1 1 1 0 0 1 2 1 1 0 0 1 0 0 1 2 0 1 1 2 0 0 1 1 2 0 0 0 2 2 1 0 1 0 1 0 1 2 2 2 2 2 2 1 0 0 0 0 ...

output:

NO

result:

ok single line: 'NO'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

10
1 1 1 1 1 1 1 1 1 2

output:

NO

result:

ok single line: 'NO'

Test #24:

score: 0
Accepted
time: 34ms
memory: 6996kb

input:

1000000
1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 2 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 0 1 2 1 0 0 1 1 1 2 1 1 0 1 1 0 1 1 2 2 2 2 2 0 0 0 2 0 0 1 1 2 1 0 1 0 0 2 0 2 2 0 0 0 1 0 1 0 2 1 0 0 0 1 2 2 0 2 2 2 0 0 0 1 1 1 0 1 1 0 1 0 2 2 1 0 1 2 0 1 0 0 1 2 1 0 0 0 0 1 0 2 2 2 1 1 0 0 0 2 1 1 1 1 1 0 1 1 1 2 2 1 0 0 1 ...

output:

NO

result:

ok single line: 'NO'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

10
1 2 2 2 2 2 2 2 2 0

output:

NO

result:

ok single line: 'NO'

Test #26:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

10
1 2 2 2 2 2 2 2 2 1

output:

YES

result:

ok single line: 'YES'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

10
1 1 1 1 1 1 1 1 1 1

output:

YES

result:

ok single line: 'YES'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

9
1 1 1 1 1 1 1 1 1

output:

NO

result:

ok single line: 'NO'

Test #29:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

10
0 0 0 0 0 0 0 0 0 0

output:

YES

result:

ok single line: 'YES'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

10
0 0 0 0 0 0 0 0 1 1

output:

YES

result:

ok single line: 'YES'

Test #31:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

5
1 0 2 0 1

output:

YES

result:

ok single line: 'YES'

Test #32:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

5
1 1 2 1 0

output:

NO

result:

ok single line: 'NO'