QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585366#1773. Breaking BarsKarL06WA 1466ms162340kbC++205.5kb2024-09-23 20:31:342024-09-23 20:31:35

Judging History

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

  • [2024-09-23 20:31:35]
  • 评测
  • 测评结果:WA
  • 用时:1466ms
  • 内存:162340kb
  • [2024-09-23 20:31:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define nL '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int long long

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const ll MOD = 1e9 + 7;

void settings()__attribute__((constructor));

void eval(bool condition) { cout << (condition ? "yes" : "no") << nL; }
void Eval(bool condition) { cout << (condition ? "Yes" : "No") << nL; }
void EVAL(bool condition) { cout << (condition ? "YES" : "NO") << nL; }

int ipow(int a, int n) {
   if (n == 0) return 1;
   int x = ipow(a, n/2);
   if (n % 2 == 0) return x*x;
   return x*x*a;
}

template <typename T>
ostream& operator<<(ostream& stream, const vector<T>& v) {
	for (auto elem : v) 
		stream << elem << " ";
	return stream;
}

template <typename T>
istream& operator>>(istream& stream, vector<T>& v){
   for(auto &elem : v)
		stream >> elem;
   return stream;
}

void settings() {
	#ifdef LOCAL
		freopen("io/input.txt", "r", stdin);
		freopen("io/output.txt", "w", stdout);
	#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
}

vector<map<vi, int>> dp;
map<pii, int> mapper;
map<int, pii> invMapper;

int toMask(const vi& a) {
	int res = 0;
	for (int i = 0; i < a.size(); i++) res += (1LL<<i)*a[i];

	return res;
}

bool emp(const vi& a) {
	bool res = true;
	for (int i = 0; i < a.size(); i++)res &= a[i] == 0;
		return res;
}

int MAX_X = 2;
int res1 = -1;
int cnt = 0;

int currX = 0;

int getDP(int t, vi& a) {
	// if (res1 != -1) cnt++;
	// if (cnt >= 1000000) return INT_MAX;
	
	if (t <= 0) return 0;
	if (dp[t].count(a)) return dp[t][a];

	// if (res1 != -1 && currX >= res1) {
	// 	return INT_MAX;
	// }

	if (emp(a) && t > 0) return INT_MAX;

	int idx = 0;
	for (int i = 20; i >= 0; i--) {
		if (a[i] > 0) {
			idx = i;
			break;
		}
	}

	pii curr = invMapper[idx];

	vi oldA = a;
	for (int i = 0; i < 21; i++) {
		if (a[i] > MAX_X) {
			int tmp = a[i]-MAX_X;
			if (tmp % 2 == 1) tmp++;
			// cout << tmp << nL;
			a[i] -= tmp;
			dp[t][oldA] = getDP(t-invMapper[i].first*invMapper[i].second*(tmp/2), a);
			a[i] += tmp;
			return dp[t][oldA];
		}
	}

	int tmp = a[idx];
	a[idx] = 0;
	dp[t][oldA] = getDP(t-curr.first*curr.second*(tmp/2), a);
	a[idx] = tmp;

	for (int i = 1; i < curr.first; i++) {
		a[idx]--;
		a[(mapper[{i, curr.second}])]++;
		a[(mapper[{curr.first-i, curr.second}])]++;

		currX++;
		dp[t][oldA] = min(dp[t][oldA], getDP(t, a)+1);
		currX--;

		a[idx]++;
		a[(mapper[{i, curr.second}])]--;
		a[(mapper[{curr.first-i, curr.second}])]--;
	}

	for (int i = 1; i < curr.second; i++) {
		a[idx]--;

		a[(mapper[{curr.first, i}])]++;
		a[(mapper[{curr.first, curr.second-i}])]++;

		currX++;
		dp[t][oldA] = min(dp[t][oldA], getDP(t, a)+1);
		currX--;

		a[idx]++;

		a[(mapper[{curr.first, i}])]--;
		a[(mapper[{curr.first, curr.second-i}])]--;
	}

	return dp[t][oldA];
}

vector<map<vi, int>> dp2;
clock_t time_req;

int getDP2(int br, vi& a) {
	if ((float)(clock()- time_req)/CLOCKS_PER_SEC > 1.5) {
		return 0;
	}
	if (dp2[br].count(a)) return dp2[br][a];
	if (br == 0) {
		int tmp = 0;
		for (int i = 0; i < 21; i++) {
			tmp += (a[i]/2)*invMapper[i].first*invMapper[i].second;
		}
		dp2[br][a] = tmp;
		return tmp;
	}

	vi oldA = a;
	dp2[br][oldA] = getDP2(br-1, a);

	int idx = 0;
	for (int i = 20; i >= 0; i--) {
		if (a[i] > 0) {
			idx = i;
			break;
		}
	}

	int tmp = a[idx];
	a[idx] = 0;
	dp2[br][oldA] = getDP2(br, a)+(tmp/2)*invMapper[idx].first*invMapper[idx].second;
	a[idx] = tmp;

	pii curr = invMapper[idx];
	for (int i = 1; i < curr.first; i++) {
		a[idx]--;
		a[(mapper[{i, curr.second}])]++;
		a[(mapper[{curr.first-i, curr.second}])]++;

		dp2[br][oldA] = max(dp2[br][oldA], getDP2(br-1, a));

		a[idx]++;
		a[(mapper[{i, curr.second}])]--;
		a[(mapper[{curr.first-i, curr.second}])]--;
	}

	for (int i = 1; i < curr.second; i++) {
		a[idx]--;

		a[(mapper[{curr.first, i}])]++;
		a[(mapper[{curr.first, curr.second-i}])]++;
		
		dp2[br][oldA] = max(dp2[br][oldA], getDP2(br-1, a));
		// cout << curr.first << " " << curr.second << " " << dp[br][oldA] << nL;
		a[idx]++;

		a[(mapper[{curr.first, i}])]--;
		a[(mapper[{curr.first, curr.second-i}])]--;
	}

	return dp2[br][oldA];
}

signed main() {
	time_req = clock();

	int idx = 0;
	for (int i = 1; i <= 6; i++) {
		for (int j = i; j <= 6; j++) {
			mapper[{i, j}] = idx;
			invMapper[idx] = {i, j};
			mapper[{j, i}] = idx++;
		}
	}

	int n, t;
	cin >> n >> t;
	vi a(21);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		a[mapper[{s[0]-'0', s[2]-'0'}]]++;
	}

	// for (int i = 0; i < 21; i++) {
	// 	t -= invMapper[i].first*invMapper[i].second*(a[i]/2);
	// 	a[i] %= 2;
	// }
	// cout << a << nL;
	dp = vector<map<vi, int>>(t+5);

	MAX_X = 1;
	res1 = getDP(t, a);
	dp2 = vector<map<vi, int>>(res1+5);
	// MAX_X = 2;
	// cout << min(res1, getDP(t, a)) << nL;

	for (int i = 0; i <= res1; i++) {
		if ((float)(clock()- time_req)/CLOCKS_PER_SEC > 1.5) {
			cout << res1 << nL;
			break;
		}
		if (getDP2(i, a) < t) continue;
		cout << i << nL;
		break;
	}
	// cout << (float)(clock()- time_req)/CLOCKS_PER_SEC << nL;

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 31ms
memory: 9580kb

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: 1ms
memory: 4000kb

input:

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

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

3 2
1x1 1x1 1x2

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 2ms
memory: 4316kb

input:

4 25
2x3 3x3 2x5 5x5

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

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

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

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

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 194ms
memory: 27780kb

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: 1ms
memory: 3892kb

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: 71ms
memory: 13240kb

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: 112ms
memory: 18192kb

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: 13ms
memory: 5904kb

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: 2ms
memory: 4004kb

input:

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

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 94ms
memory: 15404kb

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: 0ms
memory: 4472kb

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: 2ms
memory: 4060kb

input:

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

output:

2

result:

ok single line: '2'

Test #16:

score: 0
Accepted
time: 386ms
memory: 47220kb

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: 160ms
memory: 22684kb

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: 1ms
memory: 3924kb

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: 0
Accepted
time: 1438ms
memory: 160916kb

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:

9

result:

ok single line: '9'

Test #20:

score: 0
Accepted
time: 1466ms
memory: 162340kb

input:

33 197
1x5 2x1 3x6 2x1 5x5 1x4 2x2 2x6 2x4 6x3 2x1 1x3 6x5 6x1 3x2 3x3 4x3 4x6 6x6 6x1 5x2 5x2 1x6 4x4 6x2 2x1 6x5 1x5 2x1 5x6 2x3 3x6 3x5

output:

9

result:

ok single line: '9'

Test #21:

score: 0
Accepted
time: 3ms
memory: 4376kb

input:

29 458
5x6 6x6 6x6 5x6 6x6 5x6 6x6 6x5 6x5 6x6 6x5 6x6 6x5 6x6 6x6 6x6 6x5 5x6 5x5 6x6 6x5 5x5 5x5 6x5 5x6 6x6 6x5 5x5 6x5

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 161ms
memory: 26952kb

input:

29 142
1x1 5x1 3x5 1x3 5x2 2x4 1x4 1x4 5x5 4x2 1x2 5x1 5x2 2x1 5x3 2x5 4x3 3x2 4x4 2x1 1x4 6x6 1x5 5x4 2x4 3x4 4x4 5x3 1x5

output:

5

result:

ok single line: '5'

Test #23:

score: -100
Wrong Answer
time: 1441ms
memory: 147240kb

input:

29 187
6x1 5x4 4x3 6x3 2x3 2x3 1x3 6x2 4x4 5x6 6x4 3x5 5x1 6x5 5x2 5x3 5x6 5x6 1x3 2x5 3x5 2x1 2x5 1x5 1x4 3x1 4x2 2x3 4x5

output:


result:

wrong answer 1st lines differ - expected: '7', found: ''