QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589280#8936. Team Arrangementucup-team093#WA 0ms3544kbC++201.4kb2024-09-25 17:00:422024-09-25 17:00:42

Judging History

This is the latest submission verdict.

  • [2024-09-25 17:00:42]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3544kb
  • [2024-09-25 17:00:42]
  • Submitted

answer

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

using i64 = long long;
const int N = 61;
int n, l[N], r[N], w[N];

void update(map<i64, int> &mp, i64 a, int b) {
    if(!mp.count(a)) mp[a] = b;
    else if(mp[a] < b) mp[a] = b;
}

int popcount(i64 x) {
    return x ? popcount(x - (x & -x)) + 1 : 0;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i ++) {
        l[i] = 1, r[i] = n;
    }
    for(int i = 1; i <= n; i ++) w[i] = i;

    map<i64, int> mp;
    mp[0] = 0;

    for(int i = 1; i <= n; i ++) {
        vector<int> v;
        for(int j = 0; j < n; j ++) if(l[j] <= i && i <= r[j]) v.push_back(j);
        sort(v.begin(), v.end(), [](int a, int b) {return r[a] < r[b];});
        map<i64, int> nxt;
        for(auto [idx, val] : mp) {
            update(nxt, idx, val);
            if(n - popcount(idx) < i) continue;
            int cnt = 0;
            i64 k = idx;
            for(int x : v) {
                if(!((idx >> x) & 1)) { 
                    k |= 1ll << x;
                    cnt ++;
                    if(cnt == i) {
                        cnt = 0;
                        update(nxt, k, val += w[i]);
                    }
                    if(n - popcount(k) < i) break;
                }
            }
        }
        swap(nxt, mp);
    }
    if(mp.count((1ll << n) - 1)) cout << mp[(1ll << n) - 1];
    else cout << "impossible";
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3544kb

input:

3
2 3
1 2
2 2
4 5 100

output:

3

result:

wrong answer 1st lines differ - expected: '9', found: '3'