답안 #961747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961747 2024-04-12T11:57:33 Z 0npata Monster Game (JOI21_monster) C++17
25 / 100
115 ms 1452 KB
#include "monster.h"
#include<bits/stdc++.h>
using namespace std;



namespace {
#define vec vector
#define arr array
#define pb push_back
	void quick_sort(vec<int>& v, int l0, int r0, int ri = -1) {
		if(v.size() == 0) return;

		vec<int> left(0);
		vec<int> right(0);


		bool nr = ri==-1;
		if(ri == -1) {
			ri = rand()%v.size();
			ri = v[ri];
		}

		for(int i = 0; i<v.size(); i++) {
			if(v[i]==ri) continue;
			if(Query(ri, v[i])) {
				left.pb(v[i]);
			}
			else {
				right.pb(v[i]);
			}
		}

		pair<int, int> nxtl;
		pair<int, int> nxtr;
		int si = -1;
		bool sn = false;

		if(left.size() < l0) {
			int ll0 = left.size();
			nxtl = {ll0, 0};

			int lr0 = l0-(left.size()+1);
			nxtr = {lr0, r0};
		}
		else if(right.size() < r0) {
			int rr0 = right.size();
			nxtr = {0, rr0};

			int rl0 = r0-(right.size()+1);
			nxtl = {l0, rl0};
		}
		else if(v.size()-l0-r0 == 2) {
			if(left.size() > l0) {
				assert(left.size() == l0+1);
				nxtl = {l0, 1};
				nxtr = {0, r0};

				si = -2;
			}
			else {
				assert(right.size() == r0+1);
				nxtl = {l0, 0};
				nxtr = {1, r0};
				si = 2;
			}
		}
		else if(left.size() == l0) {
			assert(right.size() == r0);
			nxtl = {l0, 0};
			nxtr = {0, r0};
		}
		else if(nr && left.size() == l0+1) {
			quick_sort(v, l0, r0, left.back());
			return;
		}
		else if(nr && right.size() == r0+1) {
			quick_sort(v, l0, r0, right.front());
			return;
		}
		else {
			nxtl = {l0, 1};
			nxtr = {1, r0};

			sn = true;
		}


		int lftsz = left.size()-(nxtl.first+nxtl.second);
		int rightsz = right.size()-(nxtr.first+nxtr.second);
		if(lftsz==3 || lftsz==4 || rightsz==3 || rightsz == 4) {
			quick_sort(v, l0, r0);
			return;
		}
		quick_sort(left, nxtl.first, nxtl.second);
		quick_sort(right, nxtr.first, nxtr.second);
		if(si == -2) {
			swap(left[left.size()-1], ri);
		}
		else if(si == 2) {
			swap(right[0], ri);
		}
		if(sn) {
			swap(right[0], left[left.size()-1]);
		}

		vec<int> res = left;
		res.pb(ri);
		for(int i = 0; i<right.size(); i++)  res.pb(right[i]);

//		cerr << "RES-------------" << '\n';
//		for(int i = 0; i<res.size(); i++) cerr << res[i] << ' ';
//		cerr << '\n';
		v = res;
	}
}


std::vector<int> Solve(int n) {
  std::vector<int> v(n);


  for (int i = 0; i < n; i++) v[i] = i;

  quick_sort(v, 0, 0);

  std::vector<int> res(n);

  for(int i = 0; i<n; i++) {
	  res[v[i]] = i;
  }

  return res;
}

Compilation message

monster.cpp: In function 'void {anonymous}::quick_sort(std::vector<int>&, int, int, int)':
monster.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i = 0; i<v.size(); i++) {
      |                  ~^~~~~~~~~
monster.cpp:39:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |   if(left.size() < l0) {
      |      ~~~~~~~~~~~~^~~~
monster.cpp:46:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |   else if(right.size() < r0) {
      |           ~~~~~~~~~~~~~^~~~
monster.cpp:54:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |    if(left.size() > l0) {
      |       ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from monster.cpp:2:
monster.cpp:55:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |     assert(left.size() == l0+1);
      |            ~~~~~~~~~~~~^~~~~~~
monster.cpp:62:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |     assert(right.size() == r0+1);
      |            ~~~~~~~~~~~~~^~~~~~~
monster.cpp:68:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |   else if(left.size() == l0) {
      |           ~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from monster.cpp:2:
monster.cpp:69:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |    assert(right.size() == r0);
      |           ~~~~~~~~~~~~~^~~~~
monster.cpp:73:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |   else if(nr && left.size() == l0+1) {
      |                 ~~~~~~~~~~~~^~~~~~~
monster.cpp:77:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   77 |   else if(nr && right.size() == r0+1) {
      |                 ~~~~~~~~~~~~~^~~~~~~
monster.cpp:109:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |   for(int i = 0; i<right.size(); i++)  res.pb(right[i]);
      |                  ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 0 ms 380 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 11 ms 856 KB Output is correct
17 Correct 9 ms 856 KB Output is correct
18 Correct 12 ms 856 KB Output is correct
19 Correct 12 ms 600 KB Output is correct
20 Correct 13 ms 1364 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 7 ms 600 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 11 ms 1208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 0 ms 380 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 11 ms 856 KB Output is correct
17 Correct 9 ms 856 KB Output is correct
18 Correct 12 ms 856 KB Output is correct
19 Correct 12 ms 600 KB Output is correct
20 Correct 13 ms 1364 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 7 ms 600 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 11 ms 1208 KB Output is correct
33 Correct 58 ms 972 KB Output is correct
34 Correct 83 ms 876 KB Output is correct
35 Correct 61 ms 1124 KB Output is correct
36 Correct 59 ms 1192 KB Output is correct
37 Correct 72 ms 968 KB Output is correct
38 Correct 97 ms 724 KB Output is correct
39 Correct 66 ms 884 KB Output is correct
40 Correct 68 ms 968 KB Output is correct
41 Correct 75 ms 1220 KB Output is correct
42 Correct 64 ms 880 KB Output is correct
43 Correct 79 ms 952 KB Output is correct
44 Correct 70 ms 968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 60 ms 1104 KB Partially correct
2 Partially correct 74 ms 1384 KB Partially correct
3 Partially correct 97 ms 936 KB Partially correct
4 Partially correct 64 ms 688 KB Partially correct
5 Partially correct 76 ms 1212 KB Partially correct
6 Partially correct 72 ms 968 KB Partially correct
7 Partially correct 88 ms 972 KB Partially correct
8 Partially correct 70 ms 708 KB Partially correct
9 Partially correct 70 ms 940 KB Partially correct
10 Partially correct 67 ms 1452 KB Partially correct
11 Partially correct 79 ms 720 KB Partially correct
12 Partially correct 74 ms 1112 KB Partially correct
13 Incorrect 115 ms 1220 KB Wrong Answer [6]
14 Halted 0 ms 0 KB -