QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734438#8768. Arrested DevelopmentjiujiuWA 297ms3716kbC++201.6kb2024-11-11 10:35:362024-11-11 10:35:37

Judging History

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

  • [2024-11-11 10:35:37]
  • 评测
  • 测评结果:WA
  • 用时:297ms
  • 内存:3716kb
  • [2024-11-11 10:35:36]
  • 提交

answer

#include <bits/stdc++.h>
using ld = long double;
using i64 = long long;

#define NO std::cout << "No\n"
#define YES std::cout << "Yes\n"
#define all(x) x.begin(), x.end()

std::default_random_engine Rand;
// std::uniform_int_distribution<int> r1(1, 10);
// constexpr int d[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};

void db(){
	int n;
	std::cin >> n;
	std::vector<std::pair<int,int>> v(n);
	for(auto &[a, b] : v){
		std::cin >> a >> b;
	}
	i64 ans = 1e18;
	for(int i = 0; i <= (1ll << n); i++){
		i64 a = 0, b = 0;
		for(int j = 0; j < n; j++){
			if((i >> j) & 1){
				a += v[j].first;
			} else {
				b += v[j].second;
			}
		}
		// std::cout << a << " " << b << '\n';
		ans = std::min(ans, std::max(a, b));
	}
	std::cout << ans << "\n";
}

void solve() {
	int n;
	std::cin >> n;
	std::vector<std::pair<int,int>> v(n);
	int ans = 1e9;
	for(auto &[a, b] : v){
		std::cin >> a >> b;
	}
	for(int t = 0; t < 1000000; t++){
		std::shuffle(all(v), Rand);
		int sa = 0, sb = 0, ssa = 0, ssb = 0;
		for(int i = 0; i < n; i++){
			auto [a, b] = v[i];
			if(sa + a > sb + b) sb += b;
			else sa += a;
			if(ssa + a >= ssb + b) ssb += b;
			else ssa += a;
		}
		ans = std::min({ans, std::max(sa, sb), std::max(ssa, ssb)});
	}
	std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    Rand.seed(time(0));

    int _ = 1;

    // std::cin >> _;
    // scanf("%ld",&_);
    // std::cout<<std::fixed<<std::setprecision(2);

    while (_--) {
        solve();
        // db();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 23ms
memory: 3616kb

input:

4
100 1
1 90
1 20
1 20

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 13ms
memory: 3712kb

input:

2
314 1
592 6

output:

7

result:

ok single line: '7'

Test #3:

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

input:

1
1 1

output:

1

result:

ok single line: '1'

Test #4:

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

input:

1
100000 1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 5ms
memory: 3672kb

input:

1
1 100000

output:

1

result:

ok single line: '1'

Test #6:

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

input:

1
100000 100000

output:

100000

result:

ok single line: '100000'

Test #7:

score: 0
Accepted
time: 297ms
memory: 3680kb

input:

50
78681 95291
22639 1538
12119 52253
50430 63757
66133 92826
61048 40069
33506 30382
96049 50134
42895 62735
86943 16955
9667 61843
49647 9320
29082 16909
69601 68436
19892 34306
29822 79462
73262 14568
1693 35040
89757 61888
56993 48750
89611 77773
54159 21067
32520 41091
52501 92770
36530 17589
5...

output:

855897

result:

ok single line: '855897'

Test #8:

score: -100
Wrong Answer
time: 297ms
memory: 3680kb

input:

50
17109 75621
51243 72763
67210 97483
57809 9601
66344 79911
91593 38930
51920 44188
82765 20595
87230 78655
78390 14375
20216 46782
64273 61631
82422 38207
38700 26994
58768 59731
90891 94282
11999 82480
10537 43098
60805 6845
99773 94421
77415 93587
20930 48902
41915 46679
47122 15869
80233 45051...

output:

973144

result:

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