ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202078 | #3519. A Permutation Problem | snow_trace | 100 | 7047ms | 30596kb | C++11 | 2.4kb | 2024-02-11 12:25:47 | 2024-02-11 13:12:16 |
answer
#include<bits/stdc++.h>
using namespace std;
int ok[105][105];int n;int a[105];vector<int>v[105];
#define int long long
const int mod = 1000000007;
vector<pair<int,int> >p,p1;
bool check(int s,char x){
// cout<<s<<' '<<x<<' ';assert((s>>x&1) == 0);
for(char c = 1;;c++){
char a = x+c,b = x-c;
if(a>=n or b<0)return 1;
if(((s>>a)&1)^(s>>b&1))return 0;
}
}
#undef int
signed main(){
cin >>n;for(int i = 1;i<=n;i++)cin >>a[i];
for(int i= 1;i<=n;i++)a[i]--;
for(int i= 1;i<=n;i++){
for(int j =0;j<n;j++)ok[i][j] = 1;
if(a[i]!=-1)continue;
for(int val = 0;val<n;val++){
for(int j = 1;j<=n;j++){
if(a[j] == val)ok[i][val] = 0;
}
for(int j = i-1;j>=1;j--){
if(a[j] == -1)continue;
for(int k = i+1;k<=n;k++){
if(a[k]==-1)continue;
if(a[j]-val == val-a[k]){
ok[i][val] = 0;
}
}
}for(int j = i+1;j<=n;j++){
if(a[j] == -1)continue;
for(int k = j+1;k<=n;k++){
if(a[k] ==-1)continue;
if(a[j]-val == a[j]-a[k]){
ok[i][val] = 0;
}
}
}for(int j = i-1;j>=1;j--){
if(a[j] == -1)continue;
for(int k = j-1;k>=1;k--){
if(a[k] == -1)continue;
if(a[k]-a[j] == a[j]-val){
ok[i][val] = 0;
}
}
}
}for(int j = 0;j<n;j++)if(ok[i][j])v[i].push_back(j);
}long long tot = 0,pro = 1;
for(int i = 1;i<=n;i++)if(a[i] == -1)pro = pro*(++tot)%mod;
for(int i = 1;i<=n;i++){
for(int j = i+1;j<=n;j++){
for(int k = j+1;k<=n;k++){
if(a[i] == -1 or a[j] == -1 or a[k] == -1)continue;
if(a[i]-a[j] == a[j]-a[k]){
cout<<pro<<endl;return 0;
}
}
}
}p.push_back({0,1});
for(int i = 1;i<=n;i++){
if(a[i] == -1){p1.clear();
for(int j =0;j<p.size();j++){
long long s = p[j].first;
for(int x:v[i]){
if(s>>x&1)continue;
if(check(s,x)){
p1.push_back({s|(1ll<<x),p[j].second});
}
}
}sort(p1.begin(),p1.end());p.clear();
for(int j =0;j<p1.size();){
long long kk = p1[j].first,jj = j,tot = 0;
while(jj!=p1.size() and p1[jj].first == kk)tot+=p1[jj].second,jj++;
p.push_back({kk,tot%mod});j = jj;
}
}else{p1.clear();
for(int j =0;j<p.size();j++){
if(check(p[j].first,a[i])){
p1.push_back({p[j].first|(1ll<<a[i]),p[j].second});
}
}swap(p1,p);
}
}long long sum = 0;for(auto x:p)sum+=x.second,sum%=mod;
cout<<(pro-sum+mod)%mod<<endl;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 1256kb
input:
5 0 0 0 3 0
output:
24
result:
ok 1 number(s): "24"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1252kb
input:
5 5 0 0 0 0
output:
22
result:
ok 1 number(s): "22"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1260kb
input:
5 0 0 0 0 0
output:
100
result:
ok 1 number(s): "100"
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 1ms
memory: 1260kb
input:
9 0 0 0 0 0 0 0 0 0
output:
362384
result:
ok 1 number(s): "362384"
Test #5:
score: 0
Accepted
time: 0ms
memory: 1256kb
input:
10 0 0 0 0 0 1 0 3 0 0
output:
40318
result:
ok 1 number(s): "40318"
Test #6:
score: 0
Accepted
time: 0ms
memory: 1264kb
input:
10 0 0 0 0 0 0 0 0 0 0
output:
3627734
result:
ok 1 number(s): "3627734"
Subtask #3:
score: 10
Accepted
Test #7:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
674283947
result:
ok 1 number(s): "674283947"
Test #8:
score: 0
Accepted
time: 0ms
memory: 1272kb
input:
14 0 0 0 7 0 0 0 0 0 0 0 0 0 0
output:
227020758
result:
ok 1 number(s): "227020758"
Test #9:
score: 0
Accepted
time: 0ms
memory: 1260kb
input:
15 15 0 0 0 1 0 0 0 0 0 3 0 0 0 0
output:
479001600
result:
ok 1 number(s): "479001600"
Subtask #4:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 0ms
memory: 1268kb
input:
20 20 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 0 19
output:
425606191
result:
ok 1 number(s): "425606191"
Test #11:
score: 0
Accepted
time: 3ms
memory: 1388kb
input:
20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
143388927
result:
ok 1 number(s): "143388927"
Test #12:
score: 0
Accepted
time: 1ms
memory: 1280kb
input:
20 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
557126181
result:
ok 1 number(s): "557126181"
Subtask #5:
score: 10
Accepted
Test #13:
score: 10
Accepted
time: 0ms
memory: 1396kb
input:
25 0 0 0 0 0 0 18 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 16
output:
602640637
result:
ok 1 number(s): "602640637"
Test #14:
score: 0
Accepted
time: 8ms
memory: 1588kb
input:
25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0
output:
643345452
result:
ok 1 number(s): "643345452"
Test #15:
score: 0
Accepted
time: 9ms
memory: 1592kb
input:
25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
242322220
result:
ok 1 number(s): "242322220"
Subtask #6:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 11ms
memory: 1592kb
input:
30 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 30 0 0 0 0 0 0
output:
35757887
result:
ok 1 number(s): "35757887"
Test #17:
score: 0
Accepted
time: 7ms
memory: 1444kb
input:
30 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
597740103
result:
ok 1 number(s): "597740103"
Test #18:
score: 0
Accepted
time: 34ms
memory: 2420kb
input:
30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
343955582
result:
ok 1 number(s): "343955582"
Subtask #7:
score: 10
Accepted
Test #19:
score: 10
Accepted
time: 96ms
memory: 4304kb
input:
35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
478043548
result:
ok 1 number(s): "478043548"
Test #20:
score: 0
Accepted
time: 11ms
memory: 1848kb
input:
34 0 0 0 0 0 25 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
408748903
result:
ok 1 number(s): "408748903"
Test #21:
score: 0
Accepted
time: 89ms
memory: 4028kb
input:
35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0
output:
943272305
result:
ok 1 number(s): "943272305"
Subtask #8:
score: 10
Accepted
Test #22:
score: 10
Accepted
time: 252ms
memory: 7980kb
input:
40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
614960773
result:
ok 1 number(s): "614960773"
Test #23:
score: 0
Accepted
time: 227ms
memory: 8172kb
input:
40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22
output:
72581330
result:
ok 1 number(s): "72581330"
Test #24:
score: 0
Accepted
time: 84ms
memory: 3720kb
input:
40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 39 0 22 0 0 18 0 0 0 0 0 0 0 0
output:
354551275
result:
ok 1 number(s): "354551275"
Subtask #9:
score: 10
Accepted
Test #25:
score: 10
Accepted
time: 436ms
memory: 13524kb
input:
45 0 0 0 0 0 0 0 0 0 0 0 0 0 21 0 0 31 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 0 0 0 0 0 0 0 0 0
output:
626855450
result:
ok 1 number(s): "626855450"
Test #26:
score: 0
Accepted
time: 257ms
memory: 7716kb
input:
45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0
output:
60774616
result:
ok 1 number(s): "60774616"
Test #27:
score: 0
Accepted
time: 189ms
memory: 8400kb
input:
45 0 0 0 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
952787165
result:
ok 1 number(s): "952787165"
Subtask #10:
score: 5
Accepted
Test #28:
score: 5
Accepted
time: 794ms
memory: 20904kb
input:
47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
986042227
result:
ok 1 number(s): "986042227"
Subtask #11:
score: 5
Accepted
Test #29:
score: 5
Accepted
time: 470ms
memory: 25472kb
input:
50 0 0 0 0 0 0 0 0 43 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
82508855
result:
ok 1 number(s): "82508855"
Test #30:
score: 0
Accepted
time: 1464ms
memory: 30596kb
input:
50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
333255637
result:
ok 1 number(s): "333255637"
Test #31:
score: 0
Accepted
time: 1268ms
memory: 28168kb
input:
49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
22735711
result:
ok 1 number(s): "22735711"
Test #32:
score: 0
Accepted
time: 1336ms
memory: 29176kb
input:
50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
839694966
result:
ok 1 number(s): "839694966"
Extra Test:
score: 0
Extra Test Passed