QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258567 | #2271. High-Tech Detective | Fireball0424# | WA | 0ms | 3628kb | C++14 | 2.6kb | 2023-11-19 20:13:45 | 2023-11-19 20:13:45 |
Judging History
answer
#pragma GCC optimizer("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
//#define int long long
#define ld long double
#define ull unsigned long long
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
using namespace std;
#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}
const int mod = 1e9 + 7;
signed main(){
tofu;
int n; cin >> n;
vector<pair<char, int> > a(2 * n);
int cnt[n + 1] = {};
for(int i = 0; i < 2 * n; ++i){
cin >> a[i].fr >> a[i].sc;
cnt[a[i].sc]++;
}
vector<pair<char,int> > v;
int unknown = 0, input = 0, frac = 0;
for(auto i : a){
if(i.sc == 0 or cnt[i.sc] < 2) v.push_back(i);
if(i.fr == 'O' and i.sc == 0) unknown++;
}
for(int i = 1; i <= n; ++i) if(cnt[i] == 0) frac++;
n = (int)v.size() / 2;
int dp[2][n + 1], now = 0;
for(int i = 0; i <= n; ++i) dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for(auto i : v){
if(i.fr == 'I' and i.sc > 0){
for(int j = 0; j < unknown; ++j){
dp[now ^ 1][j + 1] += dp[now][j];
}
now ^= 1;
for(int j = 0; j <= n; ++j) dp[now][j] %= mod;
input++;
}
if(i.fr == 'I' and i.sc == 0){
for(int j = 0; j <= unknown; ++j){
dp[now ^ 1][j] += dp[now][j];
if(j + 1 <= unknown) dp[now ^ 1][j + 1] += dp[now][j];
}
now ^= 1;
for(int j = 0; j <= n; ++j) dp[now][j] %= mod;
input++;
}
if(i.fr == 'O' and i.sc > 0){
for(int j = 0; j <= n; ++j){
dp[now ^ 1][j] += dp[now][j] * (input - j);
dp[now ^ 1][j] %= mod;
}
now ^= 1;
input--;
}
if(i.fr == 'O' and i.sc == 0){
unknown--;
input--;
for(int j = 1; j <= n; ++j){
dp[now ^ 1][j - 1] += dp[now][j] * j;
dp[now ^ 1][j - 1] %= mod;
}
now ^= 1;
}
for(int j = 0; j <= n; ++j){
//cout << dp[now][j] << ' ';
dp[now ^ 1][j] = 0;
}
//db();
}
int ans = dp[now][0];
for(int i = 1; i <= frac; ++i) ans = (ans * i) % mod;
db(ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3596kb
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: 3620kb
input:
1 I 0 O 1
output:
1
result:
ok single line: '1 '
Test #4:
score: 0
Accepted
time: 0ms
memory: 3624kb
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: 3556kb
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: 3616kb
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: 3484kb
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: 0ms
memory: 3596kb
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: 3596kb
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: 0ms
memory: 3596kb
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: -100
Wrong Answer
time: 0ms
memory: 3628kb
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:
184808800
result:
wrong answer 1st lines differ - expected: '930138667', found: '184808800 '