# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
807423 | farhan132 | Monster Game (JOI21_monster) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
typedef int ll;
#define pb push_back
#define mem(a , b) memset(a, b ,sizeof(a))
const ll N = 1005;
ll dp[N][N];
ll cnt[N];
bool comp(ll a, ll b){
if(cnt[a] != cnt[b]) return cnt[a] < cnt[b];
if(dp[a][b] == a) return 1;
return 0;
}
vector < ll > make_brute(vector < ll > p){
ll n = p.size();
for(ll i = 0; i < n; i++) cnt[p[i]] = 0;
for(ll i = 0; i < n; i++){
for(ll j = 0; j < i; j++){
bool ch = Query(p[i] , p[j]);
if(ch) dp[p[i]][p[j]] = dp[p[j]][p[i]] = p[i] , cnt[p[i]]++;
else dp[p[i]][p[j]] = dp[p[j]][p[i]] = p[j] , cnt[p[j]]++;
}
}
sort(p.begin() , p.end() , comp);
return p;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less <ll>, rb_tree_tag , tree_order_statistics_node_update >
std::vector<int> Solve(int n) {
mem(dp, 0);
mem(cnt, 0);
vector < ll > ans(n , 0);
vector < ll > p;
p = merge(0 , n-1);
vector < ll > tp = p;
vector < ll > t(n , 0);
for(ll i = 0; i < p.size() - 1; i++){
t[i] = Query(p[i] , p[i + 1]);
if(i%2 == 0){
if(!t[i]) swap(tp[i] , tp[i + 1]);
}
cout << t[i] << ' ';
}
cout << '\n';
for(auto u : p) cout << u << ' ';
cout << '\n';
for(ll i = 0; i < p.size()-1; i++){
if(!t[i]){
bool ok = 0;
if(i != 0) ok = t[i - 1];
if(!t[i + 1] && !ok) swap(p[i] , p[i + 1]);
}
}
for(auto u : tp) cout << u << ' ';
cout << '\n';
//p = tp;
for(ll i = 0; i < n; i++) ans[p[i]] = i;
return ans;
}