QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623459#8790. First Billionrns_ksr#TL 23ms5664kbC++141.8kb2024-10-09 12:07:352024-10-09 12:07:35

Judging History

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

  • [2024-10-09 12:07:35]
  • 评测
  • 测评结果:TL
  • 用时:23ms
  • 内存:5664kb
  • [2024-10-09 12:07:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __float128 ld;

#define pii pair<int, int>
#define fi first
#define se second
#define VI vector<int>
#define VII vector<vector<int> >

mt19937 rnd(0);

const int N = 500500;
const int inf = 1e9 + 100;
const ll infll = 2e18 + 500;

int a[N], vis[N];

double get_rnd() {
	return 1.0 * rnd() / inf;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n / 2; i++) vis[i] = 1;
    int s = 0;
    for (int i = 1; i <= n / 2; i++) s += a[i];
    for (int i = n / 2 + 1; i <= n; i++) s -= a[i];
    int ps = 0;
    while (1) {
    	if (!s) break;
    	ps++;
    	double opt = inf;
    	int optu = -1, optv = -1;
    	for (int i = 1; i <= n; i++) {
    		int ss = s + a[i] * (vis[i] == 0 ? 2 : -2);
    		double score = abs(ss) * get_rnd();
    		if (score < opt) {
                opt = score;
                optu = i, optv = -1;
    		}
		}
    	for (int i = 1; i <= n; i++) if (vis[i] == 0) for (int j = 1; j <= n; j++) if (vis[j] == 1) {
    		int ss = s + 2 * a[i] - 2 * a[j];
    		double score = abs(ss) * get_rnd();
    		if (score < opt) {
                opt = score;
                optu = i, optv = -1;
    		}
    	}
    	if (optu > 0) {
    		s += a[optu] * (vis[optu] == 0 ? 2 : -2);
    		vis[optu] ^= 1;
    	}
    	if (optv > 0) {
    		s += a[optv] * (vis[optv] == 0 ? 2 : -2);
    		vis[optv] ^= 1;
    	}
    }
    vector<int> ans;
    for (int i = 1; i <= n; i++) if (vis[i]) ans.push_back(i);
    cout << ans.size() << ' ';
    for (auto e : ans) {
    	cout << e << ' ';
    }
    cout << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10
386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997

output:

5 1 5 6 7 9 

result:

ok OK (n = 10)

Test #2:

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

input:

10
119486233 299942886 169540407 349937991 597883752 32230162 140514533 57341098 12602102 220520836

output:

5 1 3 4 7 10 

result:

ok OK (n = 10)

Test #3:

score: 0
Accepted
time: 6ms
memory: 5608kb

input:

14
384615281 84612238 83310504 54746763 142296081 56775470 128760350 343006424 177232390 214368720 67220468 21895072 16352717 224807522

output:

7 2 3 4 5 8 11 14 

result:

ok OK (n = 14)

Test #4:

score: 0
Accepted
time: 23ms
memory: 5664kb

input:

14
270208635 14270307 89661499 113578022 47687195 101043954 38775146 208193324 650676076 351701957 3427619 59535626 24230888 27009752

output:

7 1 2 3 4 6 10 12 

result:

ok OK (n = 14)

Test #5:

score: -100
Time Limit Exceeded

input:

20
61638928 106712373 5946815 178135484 4937573 111395400 15504655 67139983 101814514 312223647 130341028 43244171 37671364 54108486 337181317 37924824 153793862 70383750 102917244 66984582

output:


result: