QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216438 | #1773. Breaking Bars | PhantomThreshold# | TL | 1301ms | 636636kb | C++14 | 2.8kb | 2023-10-15 18:18:44 | 2023-10-15 18:18:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
//map<pair<int,int>,int> dict;
int dict[55][(1<<21)+50];
int mxid=0;
int id[10][10];
int sz[25];
pair<int,int> rec[25];
int w[(1<<21)+50];
int n,W;
int x[55],y[55];
pair<int,int> pi[55];
int sum[55];
vector<pair<int,int>> v[25];
int dp[25][(1<<21)+50];
int mnans=INF;
int dfs(int dep,int mask,int nowans){
// cerr << "dfs:" << dep << " " << bitset<21>(mask) << endl;
if (sum[dep-1]-w[mask]>=W){
mnans=min(mnans,nowans);
return 0;
}
if (dep==n+1) return INF;
// if (nowans>=mnans) return INF;
// auto PAIR=make_pair(dep,mask);
if (dict[dep][mask]!=-1) return dict[dep][mask];
int ans=INF;
{
int nowid=id[x[dep]][y[dep]];
for (auto [m1,s1]:v[nowid]) ans=min(ans,dfs(dep+1,mask^m1,nowans+s1)+s1);
}
return dict[dep][mask]=ans;
}
int main(){
// freopen("B1.in","r",stdin);
ios_base::sync_with_stdio(false);
mxid=0;
for (int i=1;i<=6;i++){
for (int j=i;j<=6;j++){
id[i][j]=id[j][i]=mxid;
sz[mxid]=i*j;
rec[mxid]=make_pair(i,j);
++mxid;
}
}
for (int mask=0;mask<(1<<mxid);mask++){
for (int j=0;j<mxid;j++){
if ((mask>>j)&1) w[mask]+=sz[j];
}
}
for (int i=1;i<=6;i++){
for (int j=i;j<=6;j++){
// cerr << i << " " << j << endl;
for (int mask=0;mask<(1<<mxid);mask++) dp[id[i][j]][mask]=INF;
dp[id[i][j]][1<<id[i][j]]=0;
for (int k=1;k<=i-k;k++){
int id1=id[k][j];
int id2=id[i-k][j];
for (auto [m1,s1]:v[id1]){
for (auto [m2,s2]:v[id2]){
dp[id[i][j]][m1^m2]=min(dp[id[i][j]][m1^m2],s1+s2+1);
}
}
}
for (int l=1;l<=j-l;l++){
int id1=id[i][l];
int id2=id[i][j-l];
for (auto [m1,s1]:v[id1]){
for (auto [m2,s2]:v[id2]){
dp[id[i][j]][m1^m2]=min(dp[id[i][j]][m1^m2],s1+s2+1);
}
}
}
for (int mask=0;mask<(1<<mxid);mask++) if (dp[id[i][j]][mask]!=INF){
// if (__builtin_popcount(mask)>6) continue;
v[id[i][j]].emplace_back(mask,dp[id[i][j]][mask]);
}
sort(v[id[i][j]].begin(),v[id[i][j]].end(),
[&](const pair<int,int> &A,const pair<int,int> &B){
return A.second<B.second || (A.second==B.second && A.first>B.first);
}
);
/*
if (i<=3 && j<=5){
cerr << i << " " << j << endl;
cerr << v[id[i][j]].size() << endl;
for (auto [m1,s1]:v[id[i][j]]){
cerr << bitset<21>(m1) << "," << s1 << " ";
}
cerr << endl;
}
*/
}
}
cin >> n >> W;
W<<=1;
for (int i=1;i<=n;i++){
char ch;
cin >> x[i] >> ch >> y[i];
pi[i]=make_pair(x[i],y[i]);
}
sort(pi+1,pi+n+1);
for (int i=1;i<=n;i++){
x[i]=pi[n-i+1].first;
y[i]=pi[n-i+1].second;
}
for (int i=1;i<=n;i++) sum[i]=sum[i-1]+x[i]*y[i];
memset(dict,-1,sizeof(dict));
mnans=min(mnans,dfs(1,0,0));
cout << mnans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1301ms
memory: 636564kb
input:
16 118 5x6 3x5 4x5 6x3 6x1 1x1 4x5 4x5 2x3 1x2 5x3 5x3 6x2 3x6 5x6 4x2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 168ms
memory: 636588kb
input:
6 30 2x3 3x3 1x5 2x5 3x5 3x5
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 162ms
memory: 636636kb
input:
3 2 1x1 1x1 1x2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 175ms
memory: 636576kb
input:
4 25 2x3 3x3 2x5 5x5
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 165ms
memory: 636588kb
input:
5 10 1x1 1x1 1x1 1x1 4x4
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 170ms
memory: 636576kb
input:
6 34 1x1 1x2 2x3 3x3 5x5 5x5
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 187ms
memory: 636636kb
input:
15 70 1x1 1x2 1x3 1x4 1x5 2x2 2x3 2x4 2x5 3x3 3x4 3x5 4x4 4x5 5x5
output:
7
result:
ok single line: '7'
Test #8:
score: 0
Accepted
time: 183ms
memory: 636588kb
input:
11 40 1x1 1x2 1x3 2x3 2x4 4x5 2x2 2x2 1x4 2x4 4x5
output:
3
result:
ok single line: '3'
Test #9:
score: 0
Accepted
time: 164ms
memory: 636516kb
input:
20 74 4x3 5x1 4x2 3x3 1x2 2x1 4x2 1x5 1x1 1x4 1x1 5x5 1x4 4x5 3x2 3x5 1x2 3x4 1x1 2x3
output:
6
result:
ok single line: '6'
Test #10:
score: 0
Accepted
time: 193ms
memory: 636580kb
input:
20 104 4x2 2x3 4x5 5x1 1x3 4x3 1x2 1x1 5x2 5x4 5x5 4x1 5x5 3x5 4x2 3x1 3x1 5x4 2x1 4x4
output:
6
result:
ok single line: '6'
Test #11:
score: 0
Accepted
time: 179ms
memory: 636588kb
input:
13 44 5x4 3x2 3x2 4x1 4x4 1x2 1x5 1x2 1x1 3x5 1x2 1x3 3x2
output:
5
result:
ok single line: '5'
Test #12:
score: 0
Accepted
time: 155ms
memory: 636636kb
input:
5 21 1x3 1x2 5x4 4x4 1x1
output:
3
result:
ok single line: '3'
Test #13:
score: 0
Accepted
time: 184ms
memory: 636592kb
input:
18 77 5x4 4x2 5x5 1x4 3x1 4x3 2x3 1x1 3x4 5x2 5x3 2x2 2x1 2x1 1x2 5x3 3x3 1x4
output:
6
result:
ok single line: '6'
Test #14:
score: 0
Accepted
time: 162ms
memory: 636556kb
input:
9 30 5x2 5x3 1x4 1x4 2x3 1x2 3x3 2x3 4x1
output:
5
result:
ok single line: '5'
Test #15:
score: 0
Accepted
time: 154ms
memory: 636572kb
input:
8 37 2x4 1x3 5x4 5x5 2x4 1x4 1x2 1x4
output:
2
result:
ok single line: '2'
Test #16:
score: 0
Accepted
time: 196ms
memory: 636576kb
input:
19 103 1x5 5x2 2x2 5x4 1x5 1x1 5x5 2x2 2x5 5x4 3x4 3x2 4x4 5x4 5x3 2x2 2x4 4x3 3x3
output:
7
result:
ok single line: '7'
Test #17:
score: 0
Accepted
time: 172ms
memory: 636560kb
input:
19 75 2x1 1x1 5x5 2x4 1x3 2x3 2x2 2x3 4x5 4x3 3x1 4x1 4x2 4x4 5x1 1x4 1x5 5x3 3x1
output:
7
result:
ok single line: '7'
Test #18:
score: 0
Accepted
time: 171ms
memory: 636512kb
input:
20 81 2x3 2x5 5x3 2x1 3x1 5x2 4x5 2x1 1x5 5x2 2x5 1x5 3x2 1x5 1x2 4x2 4x2 5x4 3x2 3x3
output:
2
result:
ok single line: '2'
Test #19:
score: -100
Time Limit Exceeded
input:
47 297 3x5 3x2 1x5 5x6 5x5 5x5 4x2 5x4 4x1 6x2 6x6 5x3 1x2 2x6 6x2 3x3 2x2 2x2 1x4 2x5 5x3 4x4 6x3 3x6 5x4 3x6 3x1 6x1 3x1 1x2 3x4 1x6 6x6 5x3 1x1 5x5 2x1 1x4 5x1 5x6 2x1 4x6 2x2 6x6 2x3 6x1 3x1