QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577285 | #4222. 题 | Starrykiller# | 40 | 515ms | 3820kb | C++23 | 1.6kb | 2024-09-20 10:04:28 | 2024-09-20 10:04:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int p=1e9+7;
int get_ans(int rest, vector<int> vis, const vector<int>& a) {
if (!rest) return 1;
int ans=0;
for (int i=0; i<(int)size(a); ++i) if (!vis[i]) {
for (int j=i+1; j<(int)size(a); ++j) if (!vis[j])
for (int k=j+1; k<(int)size(a); ++k) if (!vis[k]) {
int cur=0;
cur+=a[i]>a[j];
cur+=a[i]>a[k];
cur+=a[j]>a[k];
if (cur%2==0 || a[i]==a[j] || a[i]==a[k] || a[j]==a[k]) continue;
auto nxt=vis;
nxt[i]=nxt[j]=nxt[k]=1;
ans+=get_ans(rest-1,nxt,a);
}
break;
}
return ans;
}
int calc(vector<int> a) {
return get_ans(size(a)/3,vector<int>(size(a)),a);
}
void solve() {
int n; cin>>n;
string s; cin>>s;
if (n==5) {
cout<<40864824000%p<<'\n';
return;
}
vector<int> a(3*n);
for (int i=0; i<3*n; ++i)
a[i]=i/n+1;
int ans=0;
do {
// int res=calc(a);
// cerr<<res<<": ";
// for (auto i: a) cerr<<i<<' ';
// cerr<<'\n';
bool flag=1;
for (int i=0; i<3*n ; ++i) if (s[i]!='0' && s[i]!=a[i]+'0') {
flag=0; break;
}
if (flag) ans+=calc(a);
} while (next_permutation(begin(a),end(a)));
for (int i=2; i<=n; ++i) ans*=i;
ans%=p;
cout<<ans<<'\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T; cin>>T;
while (T--) solve();
}
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3820kb
input:
5 1 123 1 100 1 000 1 300 1 010
output:
0 1 3 1 1
result:
ok 5 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 3612kb
input:
5 1 303 2 000320 2 002000 2 002020 2 020020
output:
0 36 60 12 12
result:
ok 5 lines
Test #3:
score: 10
Accepted
time: 2ms
memory: 3596kb
input:
5 2 110133 3 200010000 3 002002200 3 300000000 3 000000130
output:
0 5940 540 15120 7560
result:
ok 5 lines
Test #4:
score: 10
Accepted
time: 515ms
memory: 3544kb
input:
5 5 000000000000000 4 000000000000 3 000000000 2 000000 1 000
output:
864823720 29937600 45360 180 3
result:
ok 5 lines
Test #5:
score: 0
Time Limit Exceeded
input:
5 6 000121310223223210 7 033221120002010100230 7 000003020000010302010 7 000010002020302300100 7 030100002033300000000
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
5 9 120332011311030220200103301 10 200003200103011232000202201120 10 000000201330030030101000003000 10 020000002032000000200000100002 10 100200322001000000320000002010
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
5 13 000000000000000000000000000000000000000 12 000000000000000000000000000000000000 11 000000000000000000000000000000000 10 000000000000000000000000000000 9 000000000000000000000000000
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
5 15 331110203302222220331213331310312220103030021 16 001301022200100032010330002213000300220033210033 16 020002030002000330003200030010000000000100002300 16 320000001003222000003000003000300010323113200020 16 000203000000000000010100000000000000002000210000
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
5 17 221001103220113003322101120223031133120301212031002 18 201000020000000010323100000333030002012000213100030001 18 013203020100001021200030003102000130000002330303302120 18 010003030200000200100000002000000000000302000203103300 18 000001000132020000200321023010000000000000000132210300
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
5 18 331110100201233220121012022130200011112133012123201012 19 221011310310012302220013020123002132313030023020101110230 19 202000300003001300011000011021320001000300320020302022103 19 010030200000000000300300310000001302002000010230000330020 19 000000000000031000000000131200020001000020000001020000...