QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55125#1773. Breaking BarsMIT01TL 195ms33976kbC++172.9kb2022-10-12 12:42:072022-10-12 12:42:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-12 12:42:08]
  • 评测
  • 测评结果:TL
  • 用时:195ms
  • 内存:33976kb
  • [2022-10-12 12:42:07]
  • 提交

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;
	}
	static int pos[ty];
	REP(i, 0, ty) pos[i] = i;
	sort(pos, pos + ty, [&](int x, int y) { return sz[x] < sz[y]; });
	t = sum - t * 2;
	REP(i, 0, 1 << ty) 
	{
		int s = 0;
		int cnt = 0;
		REP(j, 0, ty)
			if (i >> pos[j] & 1) 
			{
				s += sz[pos[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)
			{
				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: 195ms
memory: 33976kb

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: 116ms
memory: 30508kb

input:

6 30
2x3 3x3 1x5 2x5 3x5 3x5

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 123ms
memory: 30644kb

input:

3 2
1x1 1x1 1x2

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 139ms
memory: 30508kb

input:

4 25
2x3 3x3 2x5 5x5

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 118ms
memory: 30632kb

input:

5 10
1x1 1x1 1x1 1x1 4x4

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 114ms
memory: 30700kb

input:

6 34
1x1 1x2 2x3 3x3 5x5 5x5

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 126ms
memory: 30740kb

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: 120ms
memory: 30572kb

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: 125ms
memory: 30724kb

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: 139ms
memory: 30676kb

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: 114ms
memory: 30660kb

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: 114ms
memory: 30492kb

input:

5 21
1x3 1x2 5x4 4x4 1x1

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 126ms
memory: 30712kb

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: 116ms
memory: 30568kb

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: 113ms
memory: 30612kb

input:

8 37
2x4 1x3 5x4 5x5 2x4 1x4 1x2 1x4

output:

2

result:

ok single line: '2'

Test #16:

score: 0
Accepted
time: 135ms
memory: 30792kb

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: 123ms
memory: 30716kb

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: 116ms
memory: 30664kb

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

output:


result: