QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558282#8941. Even or Odd Spanning Treeleafmaple#WA 1ms7600kbC++201.2kb2024-09-11 15:18:152024-09-11 15:18:17

Judging History

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

  • [2024-09-11 15:18:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7600kb
  • [2024-09-11 15:18:15]
  • 提交

answer

#include <bits/stdc++.h>
#define xs(a) cout<<setiosflags(ios::fixed)<<setprecision(a);
#define endl '\n'
using namespace std;
using ll = long long;
const int N=1e6+5;
#define int long long

array<int,2>a[N];
int w[N];
int n, res=-1e18;
int vis[N];
/*
    

*/
void dfs(int u, int ans){
    int fk = 0;
    for(int i=1; i<=n; i++)if(!vis[i])fk++;
    if(!fk){
        res = max(res, ans);
        return ;
    }
    if(u == 0){
        for(int i=1; i<=n; i++)if(!vis[i])return ;
        res = max(res, ans);
        return ;
    }
    dfs(u-1, ans);
    int cnt = 0;
    vector<int>v;
    for(int i=1; i<=n && cnt < u; i++)if(!vis[i]){
        if(a[i][0] <= u && a[i][1] >= u ){
            cnt ++;
            v.push_back(i);
        }
    }
    if(cnt == u){
        for(auto x: v)vis[x] = 1;
        dfs(u, ans + w[u]);
        for(auto x: v)vis[x] = 0;
    }
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i][0] >> a[i][1];
    sort(a+1, a+1+n, greater<array<int,2>>());
    // sort(a+1, a+1+n);
    for(int i=1; i<=n; i++) cin >> w[i];
    dfs(n, 0);
    if(res == -1e18) cout << "impossible" << endl;
    else cout << res << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7600kb

input:

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

output:

impossible

result:

wrong output format Expected integer, but "impossible" found