QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#782880 | #9802. Light Up the Grid | manba_out | WA | 11ms | 3716kb | C++20 | 1.8kb | 2024-11-25 21:59:35 | 2024-11-29 22:53:32 |
Judging History
answer
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lowbit(x) = ((x)& - (x))
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define x first
#define y second
using namespace std;
typedef long long ll;
const int N = 18;
char aa;
int t,m,ans = 0;
int a[4],f[16],d[N];
/*bitset<4> g[N];
map<bitset<4>,int> mp;
void make(bitset<4> x,vector<int>& v){
int d = x.count();
if(d==0){
int a0 = 4*a[0],a1 = 2*a[1],a2 = 2*a[2],a3 = a[3];
int ma = min(a0,max(a1,max(a2,a3)));
mp[x] = ma;
}
if(d==1){
mp[x] = a[0]+min(a[1],min(a[2],a[3]));
}
if(d == 2){
mp[x] = a[0]
}
}*/
int make(int x){
int cnt = 0;int a0 = 4*a[0],a1 = 2*a[1],a2 = 2*a[2],a3 = a[3];
int ma = min(a0,min(a1,min(a2,a3)));
rep(i,0,3){
if(x&(1<<i))++cnt;
}
if(cnt==0)return ma;
if(cnt == 1)return a[0]+min(a[1],min(a[2],a[3]));
if(cnt == 3)return a[0];
if(cnt == 2){
if(((x&1)&&(x&(1<<1)))||((x&(1<<2))&&(x&(1<<3))))return min(2*a[0],a[1]);
else if(((x&1)&&(x&(1<<2)))||((x&(1<<1))&&(x&(1<<3))))return min(2*a[0],a[2]);
else return min(2*a[0],a[1]+a[2]);
}
if(cnt == 4) return 2*ma;
}
void init(){
rep(i,0,15)f[i] = make(i);
}
bool cmp(int x,int y){
return f[x]<f[y];
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>t;
rep(i,0,3)cin>>a[i];
init();
while(t--){
ans = 0;
cin>>m;
rep(i,1,m){
d[i] = 0;
rep(j,0,3){
cin>>aa;
//while(aa!='\n')cin>>aa;
d[i] += (aa-'0')<<j;
}
}
int now = 1;
while(now<m){
sort(d+now,d+m+1,cmp);
ans+=f[d[now]];
rep(i,now+1,m){
rep(j,0,3){
if(!(d[now]&(1<<j))){
if(d[i]&(1<<j))d[i]-=(1<<j);
else d[i]+=(1<<j);
}
}
}
++now;
}
ans+=f[d[m]];
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: 3588kb
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: 3716kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 11ms
memory: 3656kb
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:
34 32 36 36 40 36 42 38 40 42 36 44 34 39 39 32 29 41 40 42 38 41 46 38 31 38 37 38 36 35 34 42 34 38 42 40 46 34 39 36 29 38 40 40 43 35 44 38 38 40 42 29 43 42 36 42 44 40 41 40 42 40 37 33 34 38 43 41 42 40 36 41 29 34 34 38 36 39 38 38 36 38 35 40 34 34 44 42 38 38 40 40 40 42 41 29 36 40 36 36 ...
result:
wrong answer 10th numbers differ - expected: '41', found: '42'