QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#54336 | #1773. Breaking Bars | KING_UT | WA | 1718ms | 137964kb | C++20 | 2.9kb | 2022-10-07 20:46:45 | 2022-10-07 20:46:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//#define int ll
using uint=unsigned;
using ull=unsigned ll;
#define gnr(i,a,b)for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define rng(i, a, b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) rng(i,0,n)
template<class t>using vc=vector<t>;
template<class t>using vvc=vc<vc<t>>;
using vi=vc<int>;
#define a first
#define b second
#define mp make_pair
using vi=vc<int>;
#define pb push_back
#define eb emplace_back
template<class t,class u>bool chmax(t &a,u b){
if(a <b){a=b;return true;}
else return false;
}
template<class t,class u>bool chmin(t &a,u b){
if(a>b){a=b;return true;}
else return false;
}
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t>void mkuni(vc<t>&vs){
sort(all(vs));
vs.erase(unique(all(vs)),vs.ed);
}
template<class t>int lwb(const vc<t>&vs,t a){
return lower_bound(all(vs),a)-vs.bg;
}
bool inc(int a,int b,int c){return a<=b&&b<=c;}
const int inf=INT_MAX/2-100;
using P=pair<int,int>;
using P1=pair<int,P>;
int getid(int h,int w){
if(h<w)swap(h,w);
return h*(h-1)/2+w-1;
}
const int smax=6;
map<int,int>ls[smax*(smax+1)/2+1];
vc<P1>dp_cur, dp_nxt;
int buff[1<<21];
void slv(){
rng(h,1,smax+1)rng(w,1,h+1){
int idx=getid(h,w);
ls[idx][1<<idx]=0;
//vert
rng(i,1,h){
int x=getid(i,w);
int y=getid(h-i,w);
for(auto u:ls[x])for(auto v:ls[y])
if(ls[idx].find(u.a^v.a) != ls[idx].end()){
chmin(ls[idx][(u.a^v.a)], u.b+v.b+1);
}
else ls[idx][u.a^v.a]=u.b+v.b+1;
}
//hori
rng(i,1,w){
int x=getid(h,i);
int y=getid(h,w-i);
for(auto u:ls[x])for(auto v:ls[y])
if(ls[idx].find(u.a^v.a) != ls[idx].end()){
chmin(ls[idx][(u.a^v.a)], u.b+v.b+1);
}
else ls[idx][u.a^v.a]=u.b+v.b+1;
}
//mkuni(ls[idx]);
//cerr<<h<<" "<<w<<" "<<si(ls[idx])<<endl;
}
int n, xx; cin >> n >> xx;
dp_cur.eb(0, P(0, 0));
int MAGIC=10000,sum=0;
rep(i, n){
string str; cin >> str;
int a = str[0]-'0';
int b = str[2]-'0';
int id = getid(a, b);
sum+=a*b;
for(auto x:dp_cur){
int val = x.a;
int now = x.b.a;
int orr = x.b.b;
if(((orr>>id)&1)){
dp_nxt.eb(val+0, P( (now^(1<<id)), (orr | (1<<id))));
continue;
}
for(auto y:ls[id]){
dp_nxt.eb(val+y.b, P( (now^y.a), (orr | y.a) ));
}
}
sort(dp_nxt.begin(), dp_nxt.end());
swap(dp_cur, dp_nxt);
dp_nxt.clear();
if((int)dp_cur.size()>MAGIC) dp_cur.resize(MAGIC);
reverse(dp_cur.begin(), dp_cur.end());
}
int ans = 1e9;
for(auto a:dp_cur){
int val = a.a;
int now = a.b.a;
int S = sum;
rng(h,1,smax+1)rng(w,1,h+1){
int idx=getid(h,w);
if(((now>>idx)&1)){
S -= h*w;
}
}
//if(S&1)cout<<S<<" "<<sum<<" "<<now<<endl;
if(S >= 2*xx){
chmin(ans, val);
}
}
cout<<ans<<endl;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
slv();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1718ms
memory: 137964kb
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: 159ms
memory: 33268kb
input:
6 30 2x3 3x3 1x5 2x5 3x5 3x5
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 22ms
memory: 3956kb
input:
3 2 1x1 1x1 1x2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 88ms
memory: 15920kb
input:
4 25 2x3 3x3 2x5 5x5
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 22ms
memory: 3880kb
input:
5 10 1x1 1x1 1x1 1x1 4x4
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 403ms
memory: 53308kb
input:
6 34 1x1 1x2 2x3 3x3 5x5 5x5
output:
2
result:
ok single line: '2'
Test #7:
score: -100
Wrong Answer
time: 797ms
memory: 77192kb
input:
15 70 1x1 1x2 1x3 1x4 1x5 2x2 2x3 2x4 2x5 3x3 3x4 3x5 4x4 4x5 5x5
output:
1000000000
result:
wrong answer 1st lines differ - expected: '7', found: '1000000000'