답안 #662872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
662872 2022-11-26T13:06:28 Z victor_gao Monster Game (JOI21_monster) C++17
0 / 100
83 ms 324 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(),5),cnt[10]={};
  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 {
    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);
    int pos=find(ans);
    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;
      }
    }
    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()){
      |          ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 208 KB Output is correct
7 Correct 0 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 Incorrect 1 ms 208 KB Wrong Answer [3]
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 208 KB Output is correct
7 Correct 0 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 Incorrect 1 ms 208 KB Wrong Answer [3]
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 308 KB Output is correct
2 Correct 69 ms 320 KB Output is correct
3 Correct 70 ms 308 KB Output is correct
4 Correct 72 ms 312 KB Output is correct
5 Correct 83 ms 316 KB Output is correct
6 Correct 65 ms 324 KB Output is correct
7 Correct 48 ms 316 KB Output is correct
8 Correct 80 ms 316 KB Output is correct
9 Incorrect 68 ms 316 KB Wrong Answer [3]
10 Halted 0 ms 0 KB -