QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793232#9802. Light Up the GridRikka_TL 1ms5616kbC++204.9kb2024-11-29 17:48:272024-11-29 17:48:32

Judging History

你现在查看的是测评时间为 2024-11-29 17:48:32 的历史记录

  • [2024-11-29 22:58:31]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:1ms
  • 内存:5728kb
  • [2024-11-29 17:48:32]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5616kb
  • [2024-11-29 17:48:27]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#define ll int
#define endl "\n"
#define lowbit(x) ((x)&(-x))
using namespace std;
ll arr[4]{};
ll n;
ll sit[16]{};
ll val[65536][16]{};
bool check[65536][16]{};
ll small[2][2][2][2]{};
ll dp(ll done, ll less) {
	if (check[done][less]) {
		return val[done][less];
	}
	check[done][less] = true;
	ll answer = 1e9;
	ll memory = done;
	while (memory) {
		ll act = lowbit(memory);
		for (ll q = 0; q < 16; ++q) {
			ll del = log2(act);
			ll used = dp(done - act, q);
			ll changes = (sit[del] ^ 15 ^ q);
			used += small[bool(changes & 8)][bool(changes & 4)][bool(changes & 2)][bool(changes & 1)];
			ll now = changes ^ q;
			now ^= less;
			used += small[bool(now & 8)][bool(now & 4)][bool(now & 2)][bool(now & 1)];
			answer = min(used, answer);
		}
		memory -= act;
	}
	return val[done][less] = answer;
}
void solve() {
	bool flag = false;
	ll n;
	cin >> n;
	for (ll q = 0; q < (1ll << n); ++q) {
		for (ll i = 0; i < 16; ++i) {
			check[q][i] = false;
		}
	}
	for (ll q = 0; q < 16; ++q) {
		check[0][q] = true;
		val[0][q] = small[bool(q & 8)][bool(q & 4)][bool(q & 2)][bool(q & 1)];
	}
	for (ll q = 0; q < n; ++q) {
		char _;
		cin >> _;
		if (_ - '0') {
			sit[q] |= 8;
		}
		cin >> _;
		if (_ - '0') {
			sit[q] |= 4;
		}
		cin >> _;
		if (_ - '0') {
			sit[q] |= 2;
		}
		cin >> _;
		if (_ - '0') {
			sit[q] |= 1;
		}
		if (sit[q] == 15) {
			flag = true;
		}
	}
	ll answer = 1e9;
	for (ll q = 0; q < 16; ++q) {
		answer = min(answer, dp((1ll << n) - 1, q));
	}
	cout << answer + flag * 2 * (min(min(arr[0], arr[1]), min(arr[2], arr[3]))) << endl;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll t = 1;
	cin >> t;
	for (ll q = 0; q < 4; ++q) {
		cin >> arr[q];
	}
	for (ll a = 0; a < 2; ++a) {
		for (ll b = 0; b < 2; ++b) {
			for (ll c = 0; c < 2; ++c) {
				for (ll d = 0; d < 2; ++d) {
					small[a][b][c][d] = 1e9;
				}
			}
		}
	}
	small[0][0][0][0] = 0;
	for (ll q = 1; q < 512; ++q) {
		ll final[4]{};
		ll finalval = 0;
		if (q & 1) {
			finalval += arr[3];
			for (ll i = 0; i < 4; ++i) {
				final[i] ^= 1;
			}
		}
		if (q & 2) {
			finalval += arr[1];
			for (ll i = 0; i < 2; ++i) {
				final[i] ^= 1;
			}
		}
		if (q & 4) {
			finalval += arr[1];
			for (ll i = 2; i < 4; ++i) {
				final[i] ^= 1;
			}
		}
		if (q & 8) {
			finalval += arr[2];
			for (ll i = 0; i < 4; i += 2) {
				final[i] ^= 1;
			}
		}
		if (q & 16) {
			finalval += arr[2];
			for (ll i = 1; i < 4; i += 2) {
				final[i] ^= 1;
			}
		}
		if (q & 32) {
			finalval += arr[0];
			final[0] ^= 1;
		}
		if (q & 64) {
			finalval += arr[0];
			final[1] ^= 1;
		}
		if (q & 128) {
			finalval += arr[0];
			final[2] ^= 1;
		}
		if (q & 256) {
			finalval += arr[0];
			final[3] ^= 1;
		}
		small[final[0]][final[1]][final[2]][final[3]] = min(finalval, small[final[0]][final[1]][final[2]][final[3]]);
	}
	while (t--) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3740kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5616kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Time Limit Exceeded

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:


result: