QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562233#8936. Team Arrangementucup-team3160#WA 0ms3752kbC++141.7kb2024-09-13 15:55:172024-09-13 15:55:18

Judging History

This is the latest submission verdict.

  • [2024-09-13 15:55:18]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3752kb
  • [2024-09-13 15:55:17]
  • Submitted

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i ++)
#define nrep(i, a, b) for(int i = (a); i >= (b); i --)
using namespace std;
void print() { cerr << endl; }
template<typename T, typename ...Ts>
void print(T x, Ts ...xs) { cerr << x << " "; print(xs...); }


typedef long long ll;
typedef unsigned long long ull;
inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
    while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x * f;
}

const int N = 100 + 10;
const ll INF = 1e17;
const ll mod = 998244353;

int n;
vector<int> vecr[N], vecl[N];
ll w[N];
pair<int, int> pr[N];
int l[N], r[N];

map<ll, ll> mp[N], vis[N];
ll ans = 0;

ll dfs(int x, ll stat) {
	if(x == 0) {
		assert(stat == 0);
		return 0;
	}
	if(vis[x][stat]) return mp[x][stat];
	ll cur = -INF;
	vis[x][stat] = 1;
	for(int i : vecr[x]) stat |= (1ll << i);
	ll mask = 0;
	for(int i : vecl[x]) mask |= (1ll << i);
	int p = n + 1, cnt = 0;
	ll now = 0;
	if((stat & mask) == 0) cur = max(cur, now + dfs(x - 1, stat));
	while((--p) > 0) if(stat & (1ll << p)) {
		stat ^= (1ll << p);
		cnt ++;
//	print (x, stat, p, cnt);
		if(cnt % x == 0) {
			now += w[x];
			if((stat & mask) == 0) cur = max(cur, now + dfs(x - 1, stat));
		}
	}
	return mp[x][stat] = cur;
}

int main() {
	n = read();
	rep(i, 1, n) {
		int l = read(), r = read();
		pr[i] = {l, r};
	}
	rep(i, 1, n) w[i] = read();
	sort(pr + 1, pr + n + 1);
	rep(i, 1, n) l[i] = pr[i].first, r[i] = pr[i].second;
	rep(i, 1, n) vecr[r[i]].push_back(i), vecl[l[i]].push_back(i);
	
	ll ans = dfs(n, 0);
	if(ans <= -INF) cout << "impossible" << endl; 
	else cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

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

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3752kb

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

7

result:

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