답안 #789675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789675 2023-07-21T17:47:32 Z PoonYaPat Monster Game (JOI21_monster) C++17
93 / 100
97 ms 4372 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;

int val[1005][1005];
vector<int> v,temp;

void rev(int l, int r) {
  while (l<r) {
    swap(v[l],v[r]);
    ++l; --r;
  }
}

int Q(int a, int b) {
  if (val[a][b]==-1) {
    int k=Query(a,b);
    val[a][b]=k;
    val[b][a]=1-k;
  }
  return val[a][b];
}

vector<int> merge_sort(int l, int r) {
  if (l==r) return {temp[l]};

  int mid=(l+r)/2;
  vector<int> L=merge_sort(l,mid), R=merge_sort(mid+1,r), res;

  int idL=0, idR=0;
  while (idL<L.size() && idR<R.size()) {
    if (!Q(L[idL],R[idR])) res.push_back(L[idL++]);
    else res.push_back(R[idR++]);
  }

  while (idL<L.size()) res.push_back(L[idL++]);
  while (idR<R.size()) res.push_back(R[idR++]);
  return res;
}

void shuf(int x) {
    if (x==0) return;
    swap(temp[rand()%x],temp[x-1]);
    shuf(x-1);
}

vector<int> Solve(int N) {
  memset(val,-1,sizeof(val));
  int n=N;
  for (int i=0; i<n; ++i) temp.push_back(i);
  shuf(n);

  v=merge_sort(0,n-1);

  //for (auto s : v) cout<<s<<" ";
  
  int cntA=0, cntB=0, st;
  for (int i=0; i<n; ++i) {
    if (i!=0 && Q(v[0],v[i])) {
      ++cntA;
      if (cntA>1) break; 
    }
  }
  for (int i=0; i<n; ++i) {
    if (i!=1 && Q(v[1],v[i])) {
      ++cntB;
      if (cntB>1) break;
    }
  }

  if (cntA==1 && cntB==1) st=1;
  else if (cntA==1) st=0;
  else {
    for (int i=2; i<n; ++i) {
      if (!Q(v[0],v[i])) {
        if (Q(v[i-1],v[i-3])) st=i-2;
        else st=i-1;
        break;
      }
    }
  }

  rev(0,st);
  int idx=st+1;
  while (idx<n) {
    int x=idx-1;
    while (!Q(v[x],v[idx]) && idx<n) ++idx;
    rev(x+1,idx);
    ++idx;
  }

  vector<int> ans(n);
  for (int i=0; i<n; ++i) ans[v[i]]=i;
  return ans;
}

Compilation message

monster.cpp: In function 'std::vector<int> merge_sort(int, int)':
monster.cpp:31:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   while (idL<L.size() && idR<R.size()) {
      |          ~~~^~~~~~~~~
monster.cpp:31:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   while (idL<L.size() && idR<R.size()) {
      |                          ~~~^~~~~~~~~
monster.cpp:36:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   while (idL<L.size()) res.push_back(L[idL++]);
      |          ~~~^~~~~~~~~
monster.cpp:37:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   while (idR<R.size()) res.push_back(R[idR++]);
      |          ~~~^~~~~~~~~
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:84:7: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   84 |   int idx=st+1;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4176 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 2 ms 4176 KB Output is correct
4 Correct 2 ms 4176 KB Output is correct
5 Correct 2 ms 4176 KB Output is correct
6 Correct 2 ms 4176 KB Output is correct
7 Correct 2 ms 4176 KB Output is correct
8 Correct 2 ms 4176 KB Output is correct
9 Correct 2 ms 4176 KB Output is correct
10 Correct 2 ms 4176 KB Output is correct
11 Correct 2 ms 4176 KB Output is correct
12 Correct 2 ms 4176 KB Output is correct
13 Correct 2 ms 4176 KB Output is correct
14 Correct 2 ms 4176 KB Output is correct
15 Correct 2 ms 4176 KB Output is correct
16 Correct 11 ms 4176 KB Output is correct
17 Correct 10 ms 4256 KB Output is correct
18 Correct 15 ms 4176 KB Output is correct
19 Correct 17 ms 4260 KB Output is correct
20 Correct 16 ms 4176 KB Output is correct
21 Correct 2 ms 4176 KB Output is correct
22 Correct 2 ms 4176 KB Output is correct
23 Correct 2 ms 4176 KB Output is correct
24 Correct 2 ms 4176 KB Output is correct
25 Correct 2 ms 4176 KB Output is correct
26 Correct 16 ms 4176 KB Output is correct
27 Correct 2 ms 4176 KB Output is correct
28 Correct 2 ms 4176 KB Output is correct
29 Correct 2 ms 4176 KB Output is correct
30 Correct 2 ms 4176 KB Output is correct
31 Correct 2 ms 4176 KB Output is correct
32 Correct 11 ms 4244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4176 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 2 ms 4176 KB Output is correct
4 Correct 2 ms 4176 KB Output is correct
5 Correct 2 ms 4176 KB Output is correct
6 Correct 2 ms 4176 KB Output is correct
7 Correct 2 ms 4176 KB Output is correct
8 Correct 2 ms 4176 KB Output is correct
9 Correct 2 ms 4176 KB Output is correct
10 Correct 2 ms 4176 KB Output is correct
11 Correct 2 ms 4176 KB Output is correct
12 Correct 2 ms 4176 KB Output is correct
13 Correct 2 ms 4176 KB Output is correct
14 Correct 2 ms 4176 KB Output is correct
15 Correct 2 ms 4176 KB Output is correct
16 Correct 11 ms 4176 KB Output is correct
17 Correct 10 ms 4256 KB Output is correct
18 Correct 15 ms 4176 KB Output is correct
19 Correct 17 ms 4260 KB Output is correct
20 Correct 16 ms 4176 KB Output is correct
21 Correct 2 ms 4176 KB Output is correct
22 Correct 2 ms 4176 KB Output is correct
23 Correct 2 ms 4176 KB Output is correct
24 Correct 2 ms 4176 KB Output is correct
25 Correct 2 ms 4176 KB Output is correct
26 Correct 16 ms 4176 KB Output is correct
27 Correct 2 ms 4176 KB Output is correct
28 Correct 2 ms 4176 KB Output is correct
29 Correct 2 ms 4176 KB Output is correct
30 Correct 2 ms 4176 KB Output is correct
31 Correct 2 ms 4176 KB Output is correct
32 Correct 11 ms 4244 KB Output is correct
33 Correct 75 ms 4248 KB Output is correct
34 Correct 67 ms 4252 KB Output is correct
35 Correct 66 ms 4240 KB Output is correct
36 Correct 89 ms 4248 KB Output is correct
37 Correct 88 ms 4248 KB Output is correct
38 Correct 97 ms 4176 KB Output is correct
39 Correct 61 ms 4248 KB Output is correct
40 Correct 70 ms 4176 KB Output is correct
41 Correct 66 ms 4248 KB Output is correct
42 Correct 62 ms 4248 KB Output is correct
43 Correct 63 ms 4244 KB Output is correct
44 Correct 58 ms 4244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 40 ms 4268 KB Partially correct
2 Partially correct 66 ms 4372 KB Partially correct
3 Partially correct 94 ms 4240 KB Partially correct
4 Partially correct 97 ms 4256 KB Partially correct
5 Partially correct 70 ms 4176 KB Partially correct
6 Correct 60 ms 4244 KB Output is correct
7 Correct 72 ms 4248 KB Output is correct
8 Partially correct 91 ms 4176 KB Partially correct
9 Partially correct 68 ms 4296 KB Partially correct
10 Partially correct 63 ms 4248 KB Partially correct
11 Partially correct 74 ms 4300 KB Partially correct
12 Partially correct 71 ms 4248 KB Partially correct
13 Correct 78 ms 4248 KB Output is correct
14 Correct 65 ms 4240 KB Output is correct
15 Correct 46 ms 4176 KB Output is correct
16 Correct 53 ms 4244 KB Output is correct
17 Correct 55 ms 4244 KB Output is correct
18 Correct 36 ms 4252 KB Output is correct