Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331#6. 「WyOJ Round 1」持 · 山海为肩__vector__00ms0kbC++232.7kb2025-04-18 19:04:172025-04-18 19:04:18

answer

# include <bits/stdc++.h>
using namespace std;
clock_t C;
const int MAXN = 1e5 + 10, MAXM = 6600;
int n, m, a[MAXN];
double f[MAXN];
int b[13], ans[13];
double mx = 0;
int pw[13], c[MAXM][MAXM];
double cnt[730][20];
int getv(int x, int y) {
	return (x / pw[y]) % 3;
}
void init() {
	pw[0] = 1;
	for (int i = 1; i <= 12; i++) {
		pw[i] = pw[i - 1] * 3;
	}
	for (int i = 0; i < pw[4]; i++) {
		for (int j = 0; j < pw[4]; j++) {
			for (int k = 0; k < 4; k++) {
				int tmp = getv(i, k) - getv(j, k);
				if (tmp == 1 || tmp == -2) c[i][j]++;
				if (tmp == -1 || tmp == 2) c[i][j]--;
			}
		}
	}
	for (int i = 0; i < pw[8]; i++) {
		for (int j = 0; j < pw[8]; j++) {
			c[i][j] = c[i / pw[4]][j / pw[4]] + c[i % pw[4]][j % pw[4]];
		}
	}
}
void dfs2(int id) {
	if (id > 12) {
		int res = 0;
		for (int i = 7; i <= 12; i++) {
			res += pw[i - 7] * b[i];
		}
		double sum = 0;
		for (int i = 0; i < pw[6]; i++) {
			int tmp = c[res][i];
			sum += cnt[i][6 - tmp];
		}
		// for (int i = 1; i <= m; i++) cout << b[i] << " " ;
		// cout << sum << endl ;
		if (sum > mx) {
			mx = sum;
			for (int i = 1; i <= 12; i++) ans[i] = b[i];
		}
		return ;
	}
	if (id > m) {
		b[id] = 0;
		dfs2(id + 1);
		return ;
	}
	for (int i = 0; i < 3; i++) {
		b[id] = i;
		dfs2(id + 1);
	}
}
void dfs(int id) {
	if (1.0 * (clock() - C) / CLOCKS_PER_SEC > 0.95) {

	printf("%.6lf\n", mx);
	for (int i = 1; i <= m; i++) {
		if (ans[i] == 0) cout << "rock ";
		else if (ans[i] == 1) cout << "paper " ;
		else cout << "scissors " ;
	}
	cout << endl ;
	exit(0);
	}
	if (id > 6) {
		for (int i = 0; i < pw[6]; i++) {
			for (int j = 0; j <= 12; j++) cnt[i][j] = 0;
		}
		int res = 0;
		for (int i = 1; i <= 6; i++) {
			res = res + pw[i - 1] * b[i];
		}
		for (int i = 1; i <= n; i++) {
			cnt[a[i] / pw[6]][c[res][a[i] % pw[6]] + 6] += f[i]; 
		}
		for (int i = 0; i < pw[6]; i++) {
			for (int j = 11; j >= 0; j--) {
				cnt[i][j] += cnt[i][j + 1];
			}
		}
		// cout << cnt[0][6] << endl ;
		// exit(0);
		dfs2(7);
		return ;
	}
	if (id > m) {
		b[id] = 0;
		dfs(id + 1);
		return ;
	}
	for (int i = 0; i < 3; i++) {
		b[id] = i;
		dfs(id + 1);
	}
}

signed main() {
	C = clock();
	init();
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> f[i];
		for (int j = 1; j <= m; j++) {
			int t;
			string s;
			cin >> s;
			if (s[0] == 'r') t = 0;
			else if (s[0] == 'p') t = 1;
			else t = 2;
			a[i] += pw[j - 1] * t;
		}
	}
	// cout << c[0][15] << " " << c[0][18] << endl ;
	dfs(1);
	printf("%.6lf\n", mx);
	for (int i = 1; i <= m; i++) {
		if (ans[i] == 0) cout << "rock ";
		else if (ans[i] == 1) cout << "paper " ;
		else cout << "scissors " ;
	}
	cout << endl ;
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Dangerous Syscalls

input:

841 5
0.002262 paper rock rock scissors scissors
0.000665 rock paper paper scissors paper
0.001132 s...

output:


result:


Test #2:

score: 0
Dangerous Syscalls

input:

320 1
0.001734 rock
0.000432 rock
0.003306 scissors
0.000322 paper
0.000380 rock
0.000817 scissors
0...

output:


result:


Test #3:

score: 0
Dangerous Syscalls

input:

19 2
0.086520 scissors rock
0.028985 rock rock
0.056406 rock scissors
0.010732 scissors rock
0.04471...

output:


result:


Test #4:

score: 0
Dangerous Syscalls

input:

100000 12
0.000008 rock rock rock scissors paper scissors paper paper paper scissors paper scissors
...

output:


result:


Test #5:

score: 0
Dangerous Syscalls

input:

82918 11
0.000009 paper rock rock scissors scissors paper rock paper rock rock paper
0.000000 scisso...

output:


result:


Test #6:

score: 0
Dangerous Syscalls

input:

63157 10
0.000004 rock scissors paper scissors paper scissors rock paper rock scissors
0.000007 rock...

output:


result:


Test #7:

score: 0
Dangerous Syscalls

input:

100000 12
0.000003 rock rock rock paper paper rock paper paper paper rock rock scissors
0.000001 pap...

output:


result:


Test #8:

score: 0
Dangerous Syscalls

input:

72055 11
0.000006 rock scissors scissors rock scissors scissors scissors scissors rock scissors scis...

output:


result:


Test #9:

score: 0
Dangerous Syscalls

input:

49463 12
0.000024 rock paper scissors paper rock scissors rock paper paper paper paper paper
0.00000...

output:


result:


Test #10:

score: 0
Dangerous Syscalls

input:

100000 12
0.000007 rock paper scissors paper paper scissors rock rock scissors rock scissors paper
0...

output:


result: