QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259757#2271. High-Tech DetectivePixelCat#RE 23ms172568kbC++201.8kb2023-11-21 13:12:072023-11-21 13:12:08

Judging History

你现在查看的是最新测评结果

  • [2023-11-21 13:12:08]
  • 评测
  • 测评结果:RE
  • 用时:23ms
  • 内存:172568kb
  • [2023-11-21 13:12:07]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 5000;
const int MOD = 1'000'000'007;

int dp[MAXN + 10][MAXN + 10];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector<int> cnt(n + 1, 0);
    vector<pii> v(n * 2);  // {1/-1, k}
    for(auto &i:v) {
        char ch; cin >> ch;
        i.F = (ch == 'I') - (ch == 'O');
        cin >> i.S;
        cnt[i.S]++;
    }
    int fac = 1;
    {
        vector<pii> swp;
        swp.eb(-1, -1);
        for(auto &i:v) {
            if(cnt[i.S] != 2) swp.eb(i);
        }
        swp.swap(v);
        int cc = 0;
        For(i, 1, n) if(cnt[i] == 0) {
            cc++;
            fac = fac * cc % MOD;
        }
    }
    int m = sz(v) - 1;

    int dif = 0;  // #I - #O
    dp[0][0] = 1;
    For(i, 1, m) {
        // cerr << v[i].F << " " << v[i].S << "\n";
        if(v[i].F > 0 && v[i].S == 0) {
            For(c, 1, m) dp[i][c] = dp[i - 1][c - 1];
        } else if(v[i].F > 0) {
            For(c, 0, m) dp[i][c] = dp[i - 1][c];
        } else if(v[i].S == 0) {
            For(c, 0, m) {
                int t = dif - c;
                if(c > 0) dp[i][c - 1] += dp[i - 1][c] * c;
                if(t > 0) dp[i][c] += dp[i - 1][c] * t;
            }
            For(c, 0, m) dp[i][c] %= MOD;
        } else {
            For(c, 1, m) dp[i][c - 1] = dp[i - 1][c] * c % MOD;
        }
        dif += v[i].F;
    }
    // For(c, 0, m / 2) For(i, 1, m) cout << dp[i][c] << " \n"[i == m];
    cout << dp[m][0] * fac % MOD << "\n";
    return 0;
}

詳細信息

Test #1:

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

input:

4
I 1
I 0
O 0
I 0
O 2
I 4
O 0
O 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

3
I 0
I 0
I 0
O 0
O 0
O 0

output:

36

result:

ok single line: '36'

Test #3:

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

input:

1
I 0
O 1

output:

1

result:

ok single line: '1'

Test #4:

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

input:

2
I 0
I 1
O 1
O 0

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
I 0
I 0
O 0
O 0
I 0
I 3
O 0
O 0

output:

24

result:

ok single line: '24'

Test #6:

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

input:

8
I 0
I 0
I 0
I 8
I 4
I 0
O 1
I 0
O 8
O 4
I 5
O 0
O 0
O 5
O 0
O 7

output:

576

result:

ok single line: '576'

Test #7:

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

input:

16
I 5
I 4
I 2
I 1
I 10
I 6
I 14
I 3
I 11
I 7
I 16
O 0
O 7
I 15
O 1
I 8
I 12
O 4
O 11
O 0
I 13
O 14
O 12
O 13
I 0
O 5
O 0
O 0
O 0
O 0
O 0
O 3

output:

2400

result:

ok single line: '2400'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5832kb

input:

50
I 42
I 32
I 29
I 14
I 27
I 0
I 9
I 18
I 11
I 25
O 31
I 39
I 41
I 23
I 43
I 1
I 35
O 25
I 44
I 5
I 28
I 48
I 33
I 50
I 21
I 19
O 29
O 33
O 19
O 44
I 17
I 6
O 32
O 23
I 30
O 42
I 13
O 27
I 20
I 34
I 15
O 17
O 30
I 36
O 0
I 0
I 10
O 21
O 36
I 40
O 34
O 9
I 4
O 20
O 14
I 47
O 1
I 22
O 50
I 26
I 24
I ...

output:

2

result:

ok single line: '2'

Test #9:

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

input:

300
I 117
I 122
I 64
I 166
I 65
I 70
I 81
I 180
I 270
I 211
I 191
I 95
I 103
I 271
O 180
I 161
I 108
I 149
I 175
I 79
I 225
I 141
I 146
I 240
I 168
I 227
I 233
I 75
I 286
I 7
I 43
I 246
I 285
I 63
I 73
I 282
I 269
I 36
I 291
I 2
I 55
I 41
O 73
I 170
I 25
I 196
I 220
I 33
I 165
I 203
O 70
I 153
I 289...

output:

12

result:

ok single line: '12'

Test #10:

score: 0
Accepted
time: 1ms
memory: 5688kb

input:

300
I 235
I 3
I 248
I 144
I 232
I 60
I 80
I 52
I 141
I 297
I 84
I 48
I 264
I 217
I 118
I 260
I 151
I 206
I 288
I 268
I 191
I 159
I 107
I 261
I 293
I 188
I 114
I 145
I 55
I 239
I 49
I 2
I 64
I 243
I 75
I 189
I 146
I 255
I 121
I 17
I 179
I 32
I 286
I 53
I 37
I 46
I 276
I 278
I 51
I 106
I 197
O 17
I 19...

output:

18

result:

ok single line: '18'

Test #11:

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

input:

100
I 8
I 51
I 60
I 48
I 79
I 90
I 42
I 15
I 29
I 21
I 33
I 68
I 91
I 73
I 30
I 12
I 96
I 74
I 95
I 54
I 40
I 7
I 45
I 44
I 28
I 2
I 22
I 23
I 20
I 72
I 63
I 67
I 13
O 22
I 88
I 32
I 24
I 17
I 70
I 16
O 16
I 56
I 97
I 86
I 89
O 0
I 61
I 3
I 19
O 0
O 0
I 11
O 0
O 0
I 47
I 100
I 64
I 92
I 82
O 97
O 0
...

output:

930138667

result:

ok single line: '930138667'

Test #12:

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

input:

100
I 0
I 0
I 0
I 0
I 0
I 99
I 0
I 0
O 0
I 0
I 84
I 0
I 29
I 0
I 0
I 0
I 0
I 22
O 0
I 4
O 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
O 0
I 95
I 0
O 38
I 0
I 0
I 0
I 31
I 0
I 0
I 0
O 0
I 0
I 32
O 0
I 0
I 65
O 0
I 0
I 0
I 0
I 0
O 0
I 28
O 0
I 0
I 0
I 0
I 0
O 0
I 0
I 47
O 0
I 17
O 0
I 0
I 39
I 0
I 0
I 42
I ...

output:

506186867

result:

ok single line: '506186867'

Test #13:

score: 0
Accepted
time: 1ms
memory: 7956kb

input:

100
I 19
I 10
I 0
I 0
I 45
I 34
I 0
I 4
I 26
I 62
I 0
I 0
I 73
I 0
I 0
O 92
I 0
I 0
I 78
I 0
I 31
I 9
I 98
I 95
I 20
I 49
I 0
I 32
I 0
O 10
O 0
I 0
I 11
I 16
I 0
I 58
I 0
I 0
I 0
I 46
O 0
I 35
I 18
I 0
I 43
I 97
I 0
I 3
I 0
O 0
I 38
I 100
I 37
O 0
I 0
I 0
O 0
I 50
I 29
I 0
I 48
O 29
O 64
I 0
O 3
O 0...

output:

640219459

result:

ok single line: '640219459'

Test #14:

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

input:

100
I 31
I 4
I 78
I 9
I 5
I 63
I 66
I 0
O 66
I 0
I 70
I 88
I 64
I 28
I 74
I 0
I 79
I 94
I 75
O 88
I 0
O 0
I 40
I 97
I 83
I 0
I 25
I 44
I 29
I 2
I 80
I 67
I 0
O 67
I 7
O 41
I 62
I 20
I 90
I 19
O 75
I 0
I 0
I 17
I 16
I 0
O 99
I 91
I 61
I 95
O 16
I 92
O 31
I 55
I 85
O 9
I 81
I 0
I 0
I 98
O 63
O 98
I 0
...

output:

720956479

result:

ok single line: '720956479'

Test #15:

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

input:

200
I 154
I 187
I 164
I 0
I 0
I 0
I 168
I 116
I 162
I 142
I 0
I 0
I 41
I 48
I 68
O 0
I 16
I 0
I 0
I 30
I 90
O 162
I 96
I 151
I 121
I 0
I 177
I 0
I 0
I 130
O 193
I 0
I 10
I 15
I 0
I 31
O 41
I 190
I 0
I 0
I 81
I 128
I 33
I 166
I 0
I 28
I 0
I 118
I 100
I 199
I 0
I 0
I 14
I 105
I 119
O 0
I 73
I 0
I 26
I...

output:

125161791

result:

ok single line: '125161791'

Test #16:

score: 0
Accepted
time: 1ms
memory: 11824kb

input:

200
I 187
I 131
I 111
I 107
I 35
I 12
I 175
I 197
I 82
I 143
I 42
I 17
I 8
I 141
I 139
I 50
I 122
I 36
I 66
I 96
I 182
I 101
O 0
I 126
I 118
O 0
I 147
I 93
I 116
I 191
I 100
I 156
I 58
I 95
I 165
I 30
I 6
I 7
I 49
I 186
I 198
I 26
I 77
I 16
I 150
I 123
I 10
I 176
I 14
I 83
I 81
I 138
I 39
I 61
I 5
I...

output:

76110076

result:

ok single line: '76110076'

Test #17:

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

input:

200
I 0
I 0
I 33
I 13
I 0
I 0
I 0
I 141
I 132
I 0
I 0
I 171
I 0
I 0
I 0
I 22
I 0
I 0
I 0
I 0
I 104
I 90
I 74
I 0
I 0
I 0
I 180
I 0
O 0
I 15
I 0
I 26
I 0
I 0
I 70
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 67
I 0
I 199
I 0
I 94
I 0
O 0
I 0
O 0
I 0
I 101
I 0
I 0
I 0
I 0
I 136
I 96
I 178
I 9
I 78
I 0
O 0
I 36
I 0
O...

output:

816352373

result:

ok single line: '816352373'

Test #18:

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

input:

300
I 142
I 117
I 3
I 101
I 201
I 0
I 104
I 251
I 230
I 198
I 0
I 83
I 203
I 0
I 255
I 102
I 0
I 11
I 0
I 0
I 157
I 0
I 0
I 211
I 109
I 0
I 279
I 204
I 124
O 104
I 0
I 0
I 0
I 18
I 44
I 0
I 33
I 268
I 0
I 36
I 60
I 207
I 224
I 70
I 223
I 75
I 0
I 103
I 195
I 0
I 0
I 122
I 96
I 111
I 0
I 138
I 0
I 7
...

output:

181020105

result:

ok single line: '181020105'

Test #19:

score: 0
Accepted
time: 3ms
memory: 26584kb

input:

300
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
I 0
I 0
I 0
I 0
I 0
I 281
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 32
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
I 0
I 0
I 0
I 0
I 0
I...

output:

14169673

result:

ok single line: '14169673'

Test #20:

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

input:

300
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
I 0
O 0
I 0
I 0
O 0
I 0
I 0
I 0
I 0
I 0
...

output:

999057162

result:

ok single line: '999057162'

Test #21:

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

input:

1000
I 0
I 446
I 327
I 910
I 547
I 0
I 0
I 933
I 28
I 119
I 0
I 0
I 0
I 559
I 0
I 30
I 0
I 63
I 776
I 838
I 260
I 0
I 0
I 433
I 14
I 78
I 0
I 0
I 89
O 596
I 566
I 594
I 68
I 0
I 615
I 634
I 616
I 0
I 47
I 0
I 0
I 493
I 524
I 708
I 832
I 940
I 858
I 759
I 276
I 309
I 440
I 918
I 0
I 188
I 945
I 0
I 0...

output:

891071351

result:

ok single line: '891071351'

Test #22:

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

input:

2000
I 0
I 1229
I 0
I 250
I 729
I 422
I 0
I 67
I 1260
I 0
I 1562
I 121
I 0
I 702
I 175
I 581
I 16
I 0
I 1646
I 816
I 0
I 0
I 1694
I 979
I 0
I 1405
I 307
I 1459
I 402
I 1809
I 1069
I 0
I 447
I 0
I 618
I 855
I 280
I 73
I 668
I 0
I 452
O 816
I 0
I 312
I 1365
I 819
I 248
I 546
I 460
I 1390
I 0
I 1164
I ...

output:

982485283

result:

ok single line: '982485283'

Test #23:

score: 0
Accepted
time: 7ms
memory: 80312kb

input:

3000
I 2124
I 211
I 2096
I 2695
I 0
I 68
I 129
I 2199
I 1900
I 0
I 0
I 2754
I 981
I 483
I 1618
I 1196
I 1568
I 1363
I 0
I 1313
I 0
I 188
I 186
I 946
I 2664
I 427
I 1512
I 1147
I 2132
I 2068
I 1815
I 1166
I 2012
I 1907
O 483
I 901
I 125
I 1806
I 2609
I 1736
I 1346
I 0
I 1886
I 1054
I 304
I 2908
I 54
...

output:

328232312

result:

ok single line: '328232312'

Test #24:

score: 0
Accepted
time: 23ms
memory: 172568kb

input:

4000
I 0
I 0
I 0
I 0
I 1795
I 1917
I 0
I 2995
I 2273
I 650
I 0
I 0
I 0
I 2599
I 2471
I 2804
I 0
I 0
I 0
I 0
I 0
I 2077
I 0
I 0
I 1705
I 0
I 898
I 0
I 327
I 0
I 0
I 0
I 1968
I 0
I 0
I 3951
I 2009
I 0
I 0
I 0
I 0
I 0
I 3647
I 0
I 1239
I 1722
I 3396
I 2936
I 2847
I 842
I 0
I 379
I 0
I 1469
I 0
I 3251
I...

output:

865132421

result:

ok single line: '865132421'

Test #25:

score: -100
Runtime Error

input:

5000
I 2314
I 4430
I 2571
I 4546
I 637
I 4407
I 2219
I 3825
I 4463
I 0
I 273
I 3676
I 1175
I 4150
I 4135
I 143
I 4223
I 4899
I 4710
I 0
I 1706
I 0
I 4299
I 4083
I 3968
I 1030
I 0
I 1576
I 715
I 0
I 2909
I 0
I 1705
I 0
I 0
I 1211
I 4152
I 1609
I 1600
I 4516
I 1927
I 0
I 4551
I 782
I 2009
I 2707
I 0
I...

output:


result: