Submission #705053

# Submission time Handle Problem Language Result Execution time Memory
705053 2023-03-03T10:01:48 Z MtSaka Monster Game (JOI21_monster) C++17
100 / 100
116 ms 912 KB
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rrep(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;i--)
#define all(x) begin(x),end(x)
using ll=long long;
using namespace std;
using ull=unsigned long long;
template<typename T,typename U>
inline bool chmax(T&a,const U&b){return (a<b)?a=b,true:false;}
template<typename T,typename U>
inline bool chmin(T&a,const U&b){return (a>b)?a=b,true:false;}
#include "monster.h"
map<pair<int,int>,bool>mp;
bool ask(int a,int b){
  if(mp.count({a,b}))return mp[{a,b}];
  if(mp.count({b,a}))return !mp[{b,a}];
  return mp[{a,b}]=Query(a,b);
}
void merge(vector<int>&v){
  if(v.size()==1)return;
  int mid=v.size()/2;
  vector<int>l(v.begin(),v.begin()+mid),r(v.begin()+mid,v.end());
  merge(l),merge(r);
  int i=0,j=0;
  rep(k,0,v.size()){
    if(i==l.size())v[k]=r[j++];
    else if(j==r.size())v[k]=l[i++];
    else if(ask(l[i],r[j]))v[k]=r[j++];
    else v[k]=l[i++];
  }
  return;
}
int sol2(const vector<int>&id){
  int n=id.size();
  vector<int>cnt(n,0);
  vector<vector<int>>a(n,vector<int>(n,0));
  rep(i,0,n)rep(j,i+1,n){
    bool f=ask(id[i],id[j]);
    if(f)cnt[i]++;
    else cnt[j]++;
    a[i][j]=f;
    a[j][i]=!f;
  }
  vector<pair<int,int>>v(n);
  rep(i,0,n)v[i]={cnt[i],id[i]};
  sort(all(v));
  if(ask(v[1].second,v[0].second))swap(v[0],v[1]);
  return v[0].second;
}
vector<int>Solve(int n){
  vector<int>id(n);
  iota(id.begin(),id.end(),0);
  merge(id);
  vector<int>tmp(id.begin(),id.begin()+min(10,n));
  int start=sol2(tmp);
  id.erase(find(all(id),start));
  id.insert(id.begin(),start);
  rep(i,1,n){
    int j=i;
    while(j<n&&ask(id[j],start))j++;
    reverse(id.begin()+i,id.begin()+min(j+1,n));
    if(j==n)break;
    start=id[j];
    i=j;
  }
  vector<int>ret(n);
  rep(i,0,n)ret[id[i]]=i;
  return ret;
}

Compilation message

monster.cpp: In function 'void merge(std::vector<int>&)':
monster.cpp:26:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     if(i==l.size())v[k]=r[j++];
      |        ~^~~~~~~~~~
monster.cpp:27:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     else if(j==r.size())v[k]=l[i++];
      |             ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 11 ms 336 KB Output is correct
17 Correct 11 ms 368 KB Output is correct
18 Correct 16 ms 352 KB Output is correct
19 Correct 13 ms 472 KB Output is correct
20 Correct 11 ms 336 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 10 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 11 ms 336 KB Output is correct
17 Correct 11 ms 368 KB Output is correct
18 Correct 16 ms 352 KB Output is correct
19 Correct 13 ms 472 KB Output is correct
20 Correct 11 ms 336 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 10 ms 304 KB Output is correct
33 Correct 56 ms 868 KB Output is correct
34 Correct 54 ms 792 KB Output is correct
35 Correct 58 ms 836 KB Output is correct
36 Correct 87 ms 748 KB Output is correct
37 Correct 87 ms 884 KB Output is correct
38 Correct 72 ms 744 KB Output is correct
39 Correct 71 ms 840 KB Output is correct
40 Correct 87 ms 864 KB Output is correct
41 Correct 103 ms 872 KB Output is correct
42 Correct 92 ms 820 KB Output is correct
43 Correct 47 ms 712 KB Output is correct
44 Correct 34 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 836 KB Output is correct
2 Correct 94 ms 816 KB Output is correct
3 Correct 69 ms 760 KB Output is correct
4 Correct 83 ms 880 KB Output is correct
5 Correct 116 ms 768 KB Output is correct
6 Correct 69 ms 732 KB Output is correct
7 Correct 45 ms 744 KB Output is correct
8 Correct 86 ms 740 KB Output is correct
9 Correct 102 ms 840 KB Output is correct
10 Correct 94 ms 912 KB Output is correct
11 Correct 42 ms 812 KB Output is correct
12 Correct 105 ms 796 KB Output is correct
13 Correct 60 ms 772 KB Output is correct
14 Correct 67 ms 728 KB Output is correct
15 Correct 43 ms 608 KB Output is correct
16 Correct 50 ms 600 KB Output is correct
17 Correct 69 ms 864 KB Output is correct
18 Correct 46 ms 788 KB Output is correct