QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#258598#2271. High-Tech DetectiveFireball0424WA 0ms3832kbC++142.4kb2023-11-19 20:48:232023-11-19 20:48:24

Judging History

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

  • [2023-11-19 20:48:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2023-11-19 20:48:23]
  • 提交

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, sure = 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];
            input++;
            sure++;
        }

        if(i.fr == 'I' and i.sc == 0){
            for(int j = 0; j <= unknown; ++j){
                dp[now ^ 1][j] = (dp[now ^ 1][j] + dp[now][j]) % mod;
                if(j + 1 <= unknown) dp[now ^ 1][j + 1] = (dp[now ^ 1][j + 1] + dp[now][j]) % mod;
            }
            input++;
        }

        if(i.fr == 'O' and i.sc > 0){
            for(int j = sure; j <= n; ++j){
                dp[now ^ 1][j] = dp[now][j] * (input - j) % mod;
            }
            input--;
        }

        if(i.fr == 'O' and i.sc == 0){
            for(int j = max(1ll, sure); j <= n; ++j){
                dp[now ^ 1][j - 1] = (dp[now][j] * j) % mod;
            }
            unknown--;
            input--;
        }

        for(int j = 0; j <= n; ++j){
            dp[now][j] = 0;
        }
        now ^= 1;
        //db();
    }

    int ans = dp[now][0];
    for(int i = 1; i <= frac; ++i) ans = (ans * i) % mod;
    db(ans);
}

詳細信息

Test #1:

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

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: 3552kb

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: 3832kb

input:

1
I 0
O 1

output:

1 

result:

ok single line: '1 '

Test #4:

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

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: 3488kb

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: 3808kb

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: -100
Wrong Answer
time: 0ms
memory: 3492kb

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:

0 

result:

wrong answer 1st lines differ - expected: '2400', found: '0 '