QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#55120 | #1773. Breaking Bars | MIT01# | WA | 124ms | 33840kb | C++17 | 2.8kb | 2022-10-12 12:24:00 | 2022-10-12 12:24:03 |
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 need[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;
int cnt = 0;
REP(j, 0, ty)
if (i >> j & 1)
{
s += sz[j];
if (s > t) ++cnt;
}
need[i] = (cnt + 2) / 3;
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)
{
if (!ok[u] && dis[u] + 1 > ans) continue;
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: 105ms
memory: 33840kb
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: 107ms
memory: 30656kb
input:
6 30 2x3 3x3 1x5 2x5 3x5 3x5
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 124ms
memory: 30612kb
input:
3 2 1x1 1x1 1x2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 109ms
memory: 30576kb
input:
4 25 2x3 3x3 2x5 5x5
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 107ms
memory: 30536kb
input:
5 10 1x1 1x1 1x1 1x1 4x4
output:
1
result:
ok single line: '1'
Test #6:
score: -100
Wrong Answer
time: 91ms
memory: 30736kb
input:
6 34 1x1 1x2 2x3 3x3 5x5 5x5
output:
3
result:
wrong answer 1st lines differ - expected: '2', found: '3'