Submission #662887

# Submission time Handle Problem Language Result Execution time Memory
662887 2022-11-26T13:12:19 Z victor_gao Monster Game (JOI21_monster) C++17
100 / 100
95 ms 440 KB
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include "monster.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
using namespace std;

vector<int> Merge(vector<int>now){
  if (now.size()<=1) return now;
  int n=now.size();
  int mid=(n-1)/2;
  vector<int>l,r;
  for (int i=0;i<=mid;i++)
    l.push_back(now[i]);
  for (int i=mid+1;i<n;i++)
    r.push_back(now[i]);
  vector<int>al=Merge(l);
  vector<int>ar=Merge(r);
  vector<int>ans;
  int p=0;
  for (int i=0;i<al.size();i++){
    if (p<ar.size()){
      if (Query(al[i],ar[p])){
        ans.push_back(ar[p]);
        p++; i--;
      }
      else ans.push_back(al[i]);
    }
    else ans.push_back(al[i]);
  }
  while (p<ar.size()){
    ans.push_back(ar[p]);
    p++;
  }
  return ans;
}
int find(vector<int>all){
  int n=min((int)all.size(),10),cnt[10]={0};
  for (int i=0;i<n;i++){
    for (int j=i+1;j<n;j++){
      if (Query(all[i],all[j])) cnt[i]++;
      else cnt[j]++;
    }
  }
  vector<int>maybe;
  for (int i=0;i<n;i++){
    if (cnt[i]==1) maybe.push_back(i);
  }
  if (maybe.size()==1) return maybe[0];
  else {
  //  cout<<all[maybe[0]]<<' '<<all[maybe[1]]<<'\n';
    if (Query(all[maybe[0]],all[maybe[1]])) return maybe[0];
    else return maybe[1];
  }
}
vector<int> Solve(int N){
    vector<int>now;
    for (int i=0;i<N;i++)
      now.push_back(i);
    vector<int>ans=Merge(now);
    /*
    for (auto i:ans)
      cout<<i<<" ";
    cout<<'\n'; 
    for (auto i:ans)
      cout<<S[i]<<" ";
    cout<<'\n';
    */
    int pos=find(ans);
   //cout<<"find "<<pos<<'\n';
    reverse(ans.begin(),ans.begin()+pos+1);
    for (int i=pos+1;i<N;i++){
      if (Query(ans[pos],ans[i])){
        reverse(ans.begin()+pos+1,ans.begin()+i+1);
        pos=i;
      }
    }
    if (pos<N) reverse(ans.begin()+pos+1,ans.begin()+N);
    vector<int>tans;
    tans.resize(N,0);
    for (int i=0;i<N;i++)
      tans[ans[i]]=i;
    return tans;
}

Compilation message

monster.cpp: In function 'std::vector<int> Merge(std::vector<int>)':
monster.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for (int i=0;i<al.size();i++){
      |                ~^~~~~~~~~~
monster.cpp:24:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if (p<ar.size()){
      |         ~^~~~~~~~~~
monster.cpp:33:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while (p<ar.size()){
      |          ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 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 1 ms 224 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 208 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 1 ms 208 KB Output is correct
16 Correct 11 ms 308 KB Output is correct
17 Correct 11 ms 208 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 15 ms 208 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 1 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 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 10 ms 208 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 1 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 1 ms 224 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 208 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 1 ms 208 KB Output is correct
16 Correct 11 ms 308 KB Output is correct
17 Correct 11 ms 208 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 15 ms 208 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 1 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 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 10 ms 208 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 65 ms 312 KB Output is correct
34 Correct 84 ms 304 KB Output is correct
35 Correct 91 ms 304 KB Output is correct
36 Correct 37 ms 304 KB Output is correct
37 Correct 95 ms 304 KB Output is correct
38 Correct 89 ms 312 KB Output is correct
39 Correct 44 ms 320 KB Output is correct
40 Correct 41 ms 436 KB Output is correct
41 Correct 77 ms 308 KB Output is correct
42 Correct 41 ms 336 KB Output is correct
43 Correct 38 ms 304 KB Output is correct
44 Correct 49 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 320 KB Output is correct
2 Correct 87 ms 320 KB Output is correct
3 Correct 55 ms 308 KB Output is correct
4 Correct 70 ms 316 KB Output is correct
5 Correct 83 ms 304 KB Output is correct
6 Correct 62 ms 308 KB Output is correct
7 Correct 64 ms 320 KB Output is correct
8 Correct 72 ms 208 KB Output is correct
9 Correct 70 ms 432 KB Output is correct
10 Correct 86 ms 320 KB Output is correct
11 Correct 85 ms 440 KB Output is correct
12 Correct 87 ms 312 KB Output is correct
13 Correct 70 ms 328 KB Output is correct
14 Correct 61 ms 316 KB Output is correct
15 Correct 42 ms 436 KB Output is correct
16 Correct 51 ms 308 KB Output is correct
17 Correct 85 ms 308 KB Output is correct
18 Correct 46 ms 308 KB Output is correct