QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793753 | #9802. Light Up the Grid | gswj | WA | 20ms | 3792kb | C++14 | 1.8kb | 2024-11-29 23:59:03 | 2024-11-29 23:59:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int g[17][17];
int all, line, col, single;
void solve(){
int n;
cin>>n;
string s, t;
vector<int> num(n, 0);
vector<bool> vis(n, false);
int now=15, min=0x3f3f3f3f3f3f3f3f, pos=-1, ans=0;
for(int i=0; i<n; i++){
cin>>s>>t;
s+=t;
num[i]=s[0]-'0'+2*(s[1]-'0')+4*(s[2]-'0')+8*(s[3]-'0');
if(num[i]==15) num[i]=16;
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(!vis[j]&&g[num[j]][now]<min){
pos=j;
min=g[num[j]][now];
}
}
// cout<<now<<" "<<num[pos]<<" "<<g[num[pos]][now]<<endl;
now=num[pos], ans+=min;
vis[pos]=true;
min=0x3f3f3f3f3f3f3f3f;
}
cout<<ans<<endl;
}
signed main(){
int t;
cin>>t;
cin>>single>>line>>col>>all;
int s[]={1, 2, 4, 8};
int a[]={15};
int l[2]={3, 12};
int c[2]={5, 10};
for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
g[i][j]=0x3f3f3f3f3f3f3f3f;
}
for(int j=0; j<4; j++){
g[i][i^s[j]]=min(g[i][i^s[j]], single);
}
for(int j=0; j<2; j++){
g[i][i^l[j]]=min(g[i][i^l[j]], line);
g[i][i^c[j]]=min(g[i][i^c[j]], col);
}
g[i][i^a[0]]=min(g[i][i^a[0]], all);
}
for(int k=0; k<16; k++){
for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
g[i][j]=min(g[i][j], g[i][k]+g[k][j]);
}
}
}
for(int j=0; j<16; j++) {
g[16][j] = g[15][j];
}
// cout<<g[16][15]<<endl;
// cout<<"here"<<endl;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3792kb
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
1121 2
result:
ok 2 number(s): "1121 2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
2 1 1 1 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
5 2
result:
ok 2 number(s): "5 2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 20ms
memory: 3576kb
input:
10000 8 2 7 8 8 00 01 00 11 00 10 11 11 10 10 01 10 01 00 10 11 8 11 01 11 00 01 10 11 11 00 01 01 01 01 00 11 10 9 00 00 01 01 10 11 00 01 11 10 11 00 11 11 00 11 01 10 9 11 11 10 00 11 00 11 01 00 10 01 11 00 01 01 01 10 01 11 00 01 01 01 10 10 00 11 11 11 11 10 ...
output:
28 27 29 31 39 38 42 38 40 37 34 42 34 37 39 27 29 36 40 40 38 33 42 29 25 37 29 38 34 28 32 35 35 36 35 38 37 34 39 36 29 29 35 36 42 39 31 31 38 33 40 29 35 33 36 37 46 33 41 27 40 40 29 31 34 33 31 38 42 40 32 29 29 34 34 33 31 39 34 38 32 31 26 29 29 34 39 42 34 33 40 43 31 36 31 25 36 40 38 36 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '28'