QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592614#881. Gig CombinatoricsZDHKLVWA 0ms3628kbC++141.3kb2024-09-27 00:39:472024-09-27 00:39:48

Judging History

This is the latest submission verdict.

  • [2024-09-27 00:39:48]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3628kb
  • [2024-09-27 00:39:47]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

int main() {

    int n;
    cin >> n;

    int N1 = 0, N3 = 0;
    int *X = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> X[i];
        if (X[i] == 1) N1++;
        else if (X[i] == 3) N3++;
    }

    if (N1 == 0 || N3 == 0) {
        cout << 0 << endl;
        return 0;
    }

    int *indexes_1 = new int[N1];
    int *indexes_3 = new int[N3];

    {
        int i1 = 0, i3 = 0;

        for (int i = 0; i < n; i++) {
            if (X[i] == 1) indexes_1[i1++] = i;
            else if (X[i] == 3) indexes_3[i3++] = i;
        }
    }

    const int mod = (int) 1e9 + 7;

    int output = 0;

    for (int i = 0; i < N1; i++) {

        int pos_1 = indexes_1[i];
        int begin_j = lower_bound(indexes_3, indexes_3+N3, pos_1) - indexes_3;

        int j = begin_j;
        while (j < N3) {
            int pos_3 = indexes_3[j];

            int count_3 = j - begin_j;
            
            int pos_rightest_1_before_3 = upper_bound(indexes_1+i, indexes_1+N1, pos_3) - indexes_1-1;

            int count_1 = pos_rightest_1_before_3 - i;
            int count_2 = pos_3 - pos_1 - 1 - count_1 - count_3;

            int add = (int) (((long long) (1 << count_2)) % mod - 1);
            output = (output + add) % mod;

            j++;
        }

    }

    cout << output << endl;

    return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

9
1 1 1 2 2 2 3 3 3

output:

63

result:

ok answer is '63'

Test #2:

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

input:

8
1 2 1 2 3 1 2 3

output:

15

result:

ok answer is '15'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3628kb

input:

310
1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 1 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 2 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 2 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 1 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 ...

output:

613030068

result:

wrong answer expected '265702265', found '613030068'