QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#828677#9842. Modulesuper_milk_dragon_bang3WA 509ms247076kbC++141.0kb2024-12-23 19:30:232024-12-23 19:30:25

Judging History

This is the latest submission verdict.

  • [2024-12-23 19:30:25]
  • Judged
  • Verdict: WA
  • Time: 509ms
  • Memory: 247076kb
  • [2024-12-23 19:30:23]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PII array<int,2>
#define PI3 array<int,3>

const ll N = 1e5 + 5, mod = 998244353, INF = 1e9;

ll a[21], dp[21][1<<21];
vector<int> b[1<<21];

inline void update(ll &x, ll y) {
	if(x < y) x = y;
}

void solve() {
	int n; cin >> n; int m = 1 << n;
	for(int i = 0; i < n; ++ i)cin >> a[i];
	ll x; cin >> x;
	
	for(int i=m-1; i; i--) {
		for(int j=0; j<n; j++) if(i>>j&1) b[i].emplace_back(j);
	}
	
	for(int sta = 1, lst_sta; sta < m; ++ sta){
		for(auto const &i: b[sta]) {
			lst_sta = sta ^ (1 << i);
			if(lst_sta == 0){
				dp[i][sta] = x % a[i];
				break;
			}else{
				for(auto const &j: b[lst_sta]) {
					if(n < 15)
						update(dp[i][sta], dp[j][lst_sta] >= a[i] ? dp[j][lst_sta] % a[i] : dp[j][lst_sta]);
				}
			}
		}
	}
	
	ll ans = 0;
	for(int i=0; i<n; i++) ans = max(ans, dp[i][m-1]);
	cout << ans;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int t = 1; //cin >> t;
	while(t --) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 57932kb

input:

3
5 6 7
15

output:

3

result:

ok single line: '3'

Test #2:

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

input:

4
20 21 22 10
107

output:

9

result:

ok single line: '9'

Test #3:

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

input:

5
5 6 7 8 9
1000000000000

output:

4

result:

ok single line: '4'

Test #4:

score: -100
Wrong Answer
time: 509ms
memory: 247076kb

input:

21
387370091048596 23758943242091 1014205329284566 1140429273127661 47646521198630614 18199351186587118 140264880946836239 2655245896805102 56344740535070 6951532361130740 7919647866064 7816692309555091 147904943861222 2985707194227584 20464369734437689 7043092696894 166312602338536 21129277743988 4...

output:

0

result:

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