QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#638519 | #7014. Rikka with Grid Graphs | tarjen | AC ✓ | 1652ms | 3980kb | C++20 | 2.9kb | 2024-10-13 16:07:39 | 2024-10-13 16:07:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(){
int n,m;cin>>n>>m;getchar();
vector<string> s(2*n);
for(int i=0;i<2*n-1;i++){
getline(cin,s[i]);
while(s[i].size()<2*m)s[i].push_back(' ');
}
auto queryup = [&](int x,int y){
return x>0&&s[x*2-1][y*2]=='|';
};
auto queryleft = [&](int x,int y){
return y>0&&s[x*2][y*2-1]=='-';
};
map<ll,ll> dp;
dp[0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
map<ll,ll> dp2;
for(auto [bit,val]:dp){
array<array<int,7>,7>f;
for(int x=0;x<7;x++){
for(int y=0;y<7;y++)f[x][y]=0;
}
for(int x=0;x<6;x++){
for(int y=0;y<6;y++){
if(bit>>(x*7+y)&1)f[x][y]=1;
}
}
auto sol = [&](vector<pair<int,int>> &edges){
auto g=f;
// cout<<"sol bit="<<bit<<" val="<<val<<endl;
// for(auto [x,y]:edges)cout<<"x="<<x<<" y="<<y<<endl;
for(auto [x,y]:edges)if(x!=-1&&y!=-1)g[x][y]=1;
// for(int i=0;i<7;i++){
// for(int j=0;j<7;j++){
// cout<<g[i][j];;
// }
// cout<<endl;
// }
for(int i=0;i<7;i++){
for(int j=0;j<7;j++){
for(int k=0;k<7;k++)g[j][k]|=(g[j][i]&g[i][k]);
}
}
for(int i=0;i<7;i++){
if(g[i][i]){
return;
}
}
ll nowb=0;
for(int x=0;x<7;x++)if(x!=j){
for(int y=0;y<7;y++)if(y!=j&&g[x][y]){
nowb|=(1ll<<((x==6?j:x)*7+(y==6?j:y)));
}
}
// cout<<"nowb="<<nowb<<" val="<<val<<endl;
dp2[nowb]+=val;
};
vector<pair<int,int>> edges(2,make_pair(-1,-1));
for(int p=0;p<(queryleft(i,j)?2:1);p++){
if(queryleft(i,j)){
edges[0]=p?make_pair(6,j-1):make_pair(j-1,6);
}
for(int q=0;q<(queryup(i,j)?2:1);q++){
if(queryup(i,j)){
edges[1]=q?make_pair(6,j):make_pair(j,6);
}
sol(edges);
}
}
}
dp=dp2;
}
}
ll ans=0;
for(auto [x,y]:dp)ans+=y;
return ans;
}
int main()
{
int T;cin>>T;
while(T--)cout<<solve()<<"\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
4 2 2 +-+ + + 2 2 +-+ | + + 2 2 +-+ | +-+ 2 2 +-+ | | +-+
output:
2 4 8 14
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1652ms
memory: 3980kb
input:
60 1 1 + 6 6 +-+-+-+-+-+ | | | | | | +-+-+-+-+-+ | | | | | | +-+-+-+-+-+ | | | | | | +-+-+-+-+-+ | | | | | | +-+-+-+-+-+ | | | | | | +-+-+-+-+-+ 6 4 + + + + + + + + + + + + + + + + + + + + + + + + 4 5 +-+-+-+ + | | +-+-+-+ + | | +-+ +-+ + | | + + +-+ + 5 6 + + +-+ + + | | | | | +-...
output:
1 39931856138212664 1 32768 2097152 396928 1912140726272 17072685056 33681342464 1070508371744 4877910016 470169766912 181121759168 814322432 891691528874048 358663151840 1905966526844408 851738327552 191458384162304 288115586432 1368156669845336 356038587648896 3776487925133468 691176008890304 1090...
result:
ok 60 lines