답안 #492658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492658 2021-12-08T10:51:03 Z Jarif_Rahman Monster Game (JOI21_monster) C++17
0 / 100
85 ms 4404 KB
#include "monster.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
 
#ifdef LOCAL
#define debug(v) for(auto x: v) cerr << x << " "; cerr << #v << "\n";
#endif
 
vector<vector<int>> QQ;
bool query(int a, int b){
    if(a > b){
        if(QQ[b][a] == -1) QQ[b][a] = Query(b, a);
        return !QQ[b][a];
    }
    else{
        if(QQ[a][b] == -1) QQ[a][b] = Query(a, b);
        return QQ[a][b];
    }
}
 
template<typename it>
void merge_sort(it a, it b){
    int n = b-a;
    if(n == 1) return;
    merge_sort(a, a+n/2);
    merge_sort(a+n/2, b);
    int* ab = new int[n];
    merge(a, a+n/2, a+n/2, b, ab, [&](int x, int y){
        return query(y, x);
    });
    for(int i = 0; i < n; i++) *(a+i) = *(ab+i);
}
 
vector<int> Solve(int n){
    QQ = vector<vector<int>>(n, vector<int>(n, -1));
 
    vector<int> sth(n);
    for(int i = 0; i < n; i++) sth[i] = i;
    random_shuffle(sth.begin(), sth.end());
    merge_sort(sth.begin(), sth.end());
 
    auto win = [=](int x){
        vector<int> rt;
        for(int i = 0; i < n; i++) if(i != x && query(x, i)) rt.pb(i);
        return rt;
    };

    int z = -1, k = min(n, 10);
    vector<int> cnt(k, 0), ss(k);
    for(int i = 0; i < k; i++) ss[i] = i;
    for(int i = 0; i < k; i++){
        for(int j = 0; j < k; j++) if(i != j) cnt[i]+=query(sth[i], sth[j]);
    }

    sort(ss.begin(), ss.end(), [&](int x, int y){
        return cnt[x] < cnt[y];
    });
    if(query(ss[0], ss[1])) z = ss[1];
    else z = ss[0];

    reverse(sth.begin(), sth.begin()+z+1);

    for(;z+1 < n; z++){
        for(int i = z+1; i < n; i++) if(query(sth[z], sth[i])){
            reverse(sth.begin()+z+1, sth.begin()+i+1);
            z = i;
        }
    }
 
    vector<int> ans(n);
    for(int i = 0; i < n; i++) ans[sth[i]] = i;
    return ans;
}

Compilation message

monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:47:10: warning: variable 'win' set but not used [-Wunused-but-set-variable]
   47 |     auto win = [=](int x){
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 4264 KB Output is correct
2 Correct 73 ms 4252 KB Output is correct
3 Incorrect 85 ms 4404 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -