QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#55117 | #1773. Breaking Bars | MIT01# | TL | 37ms | 25808kb | C++17 | 2.6kb | 2022-10-12 12:17:44 | 2022-10-12 12:17:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb emplace_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
template<typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
typedef long long LL;
const int oo = 0x3f3f3f3f;
const int ty = 21;
int id[7][7];
bool ok[1 << ty];
//LL dp[1 << ty];
int dis[1 << ty];
int sz[ty];
vector<pair<int, int> > nxt[ty];
inline void init(int x, int y, int p)
{
sz[p] = x * y;
set<pair<int, int> > s0;
map<int, int> s1;
REP(i, 1, (x >> 1) + 1)
{
s0.insert(mp(id[i][y], id[x - i][y]));
}
REP(i, 1, (y >> 1) + 1)
{
s0.insert(mp(id[x][i], id[x][y - i]));
}
for (auto u : s0) for (auto a : nxt[u.x]) for (auto b : nxt[u.y])
if (s1.count(a.x ^ b.x)) chkmin(s1[a.x ^ b.x], a.y + b.y + 1);
else s1[a.x ^ b.x] = a.y + b.y + 1;
s1.insert(mp(1 << p, 0));
for (auto u : s1) nxt[p].pb(u);
}
int vis[1 << ty];
const int maxn = 51;
pair<int, int> a[maxn + 5];
int nxtdis[1 << ty];
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
{
int cnt = 0;
REP(i, 1, 7)
REP(j, 1, i + 1)
{
init(i, j, cnt);
id[i][j] = id[j][i] = cnt++;
}
assert(cnt == ty);
}
int n, t;
int sum = 0;
scanf("%d%d", &n, &t);
REP(i, 0, n)
{
int x, y;
scanf("%dx%d", &x, &y);
a[i] = mp(x, y);
sum += x * y;
}
t = sum - t * 2;
REP(i, 0, 1 << ty)
{
int s = 0;
REP(j, 0, ty)
if (i >> j & 1) s += sz[j];
if (s <= t) ok[i] = 1;
else ok[i] = 0;
}
memset(dis, oo, sizeof dis);
int ans = 0;
memset(vis, -1, sizeof vis);
int tmp = 0;
while (1)
{
vis[0] = tmp;
dis[0] = 0;
vector<int> cur, Nxt;
cur.pb(0);
REP(i, 0, n)
{
Nxt.clear();
for (auto u : cur)
{
for (auto v : nxt[id[a[i].x][a[i].y]])
{
if (dis[u] + v.y <= ans)
{
if (vis[u ^ v.x] != tmp)
{
vis[u ^ v.x] = tmp;
Nxt.pb(u ^ v.x);
nxtdis[u ^ v.x] = dis[u] + v.y;
}
else
{
chkmin(nxtdis[u ^ v.x], dis[u] + v.y);
}
}
}
}
++tmp;
cur = Nxt;
for (auto u : cur) dis[u] = nxtdis[u];
}
bool found = 0;
for (auto u : cur)
if (ok[u])
{
found = 1;
}
if (found) break;
++ans;
}
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 34ms
memory: 25808kb
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: 27ms
memory: 22304kb
input:
6 30 2x3 3x3 1x5 2x5 3x5 3x5
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 15ms
memory: 22424kb
input:
3 2 1x1 1x1 1x2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 13ms
memory: 22332kb
input:
4 25 2x3 3x3 2x5 5x5
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 19ms
memory: 22292kb
input:
5 10 1x1 1x1 1x1 1x1 4x4
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 26ms
memory: 22496kb
input:
6 34 1x1 1x2 2x3 3x3 5x5 5x5
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 27ms
memory: 22660kb
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: 11ms
memory: 22468kb
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: 32ms
memory: 22604kb
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: 31ms
memory: 22644kb
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: 11ms
memory: 22492kb
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: 17ms
memory: 22464kb
input:
5 21 1x3 1x2 5x4 4x4 1x1
output:
3
result:
ok single line: '3'
Test #13:
score: 0
Accepted
time: 27ms
memory: 22504kb
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: 21ms
memory: 22372kb
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: 11ms
memory: 22352kb
input:
8 37 2x4 1x3 5x4 5x5 2x4 1x4 1x2 1x4
output:
2
result:
ok single line: '2'
Test #16:
score: 0
Accepted
time: 37ms
memory: 22544kb
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: 31ms
memory: 22624kb
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: 11ms
memory: 22516kb
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