QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283093 | #1191. Reordering the Documents | NYCU_template# | WA | 2ms | 5128kb | C++14 | 2.2kb | 2023-12-13 20:14:11 | 2023-12-13 20:14:11 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define M 1000000007
using namespace std;
bool solve(){
int n, m;
if(!(cin >> n >> m)) return false;
int a[n], b[n];
for(auto &x : a) {
cin >> x;
x--;
}
for(int i = 0; i < n; ++i)
b[a[i]] = i;
vector<pair<ll, ll>> t;
bool v1[n]{false}, v2[n]{false}, can = true;
for(int i = n-1; i >= 0; i--){
if(v1[i]) continue;
v1[i] = true; v2[b[i]] = true;
ll c1 = 1, c2 = 0;
int mn = INT_MAX;
if(b[i]+1 < n && !v2[b[i]+1]) {
mn = a[b[i]+1];
c2++;
v1[a[b[i]+1]] = v2[b[i]+1] = true;
for(int s = b[i]+2; s < n && !v2[s]; ++s){
if(a[s-1] > a[s]){
can = false; break;
}
c2++;
v1[a[s]] = v2[s] = true;
}
}
for(int s = b[i]-1; s >= 0; --s){
if(a[s] > mn) {
c1++;
v2[s] = v1[a[s]] = true;
}
else break;
}
// cerr << c1 << ' ' << c2 <<'\n';
t.push_back({c1,c2});
// cerr << i << " : ";
// cerr << c1 << ' ' << c2 << '\n';
}
if(!can) {
cout << 0 << '\n';
return true;
}
int A = t[0].F + t[0].S;
// cerr << A << '\n';
vector<vector<ll>> dp(m+1, vector<ll>(m+1, 0));
dp[t[0].F][t[0].S] += 1;
dp[t[0].S][t[0].F] += 1;
// cerr << t[0].F << ' ' << t[0].S << '\n';
// for(auto &x : dp){
// for(auto &y : x) cout << y << ' ';
// cerr << '\n';
// }
for(int i = 1; i < t.size(); ++i){
for(int j = 0; j <= A; ++j){
// cerr << i << ' ' << j << ' ' << A << '\n';
if(t[i].F + j <= m && t[i].S + A - j <= m){
dp[t[i].F + j][t[i].S + A - j] += dp[j][A - j];
dp[t[i].F + j][t[i].S + A - j] %= M;
}
if(t[i].S + j <= m && t[i].F + A - j <= m){
dp[t[i].S + j][t[i].F + A - j] += dp[j][A - j];
dp[t[i].S + j][t[i].F + A - j] %= M;
}
}
// for(auto &x : dp){
// for(auto &y : x) cout << y << ' ';
// cerr << '\n';
// }
A += t[i].F + t[i].S;
}
// for(auto &x : dp){
// for(auto &y : x) cout << y << ' ';
// cout << '\n';
// }
ll ans = 0;
for(int i = 0; i <= n; ++i){
if(i <= m && n-i <= m) ans += dp[i][n-i];
}
cout << ans << '\n';
return true;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
while(solve());
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3432kb
input:
6 3 1 3 4 2 6 5
output:
4
result:
ok answer is '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
6 6 1 3 4 2 6 5
output:
8
result:
ok answer is '8'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
4 4 4 3 1 2
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
6 3 1 3 4 2 6 5
output:
4
result:
ok answer is '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
6 6 1 3 4 2 6 5
output:
8
result:
ok answer is '8'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
4 4 4 3 1 2
output:
0
result:
ok answer is '0'
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 5128kb
input:
1000 500 4 5 6 8 10 11 12 13 14 15 20 23 25 26 28 29 33 35 1 2 36 38 3 7 41 9 16 44 48 17 18 51 52 53 19 21 54 22 24 59 61 62 27 67 30 31 32 34 68 69 37 39 73 40 76 77 42 81 83 43 85 45 87 46 89 94 47 95 49 50 97 101 55 103 105 56 57 58 106 60 108 110 63 111 114 64 115 65 119 66 70 71 120 121 72 124...
output:
375563758
result:
wrong answer expected '11363968', found '375563758'