Submission #961746

# Submission time Handle Problem Language Result Execution time Memory
961746 2024-04-12T11:55:17 Z 0npata Monster Game (JOI21_monster) C++17
25 / 100
128 ms 1640 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;
		}


		if(left.size()-(nxtl.first+nxtl.second)==3 || right.size()-(nxtr.first+nxtr.second) == 3) {
			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:107:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for(int i = 0; i<right.size(); i++)  res.pb(right[i]);
      |                  ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 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 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 9 ms 700 KB Output is correct
17 Correct 11 ms 600 KB Output is correct
18 Correct 8 ms 692 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 7 ms 604 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 7 ms 608 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 596 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 8 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 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 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 9 ms 700 KB Output is correct
17 Correct 11 ms 600 KB Output is correct
18 Correct 8 ms 692 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 7 ms 604 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 7 ms 608 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 596 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 8 ms 856 KB Output is correct
33 Correct 74 ms 1228 KB Output is correct
34 Correct 93 ms 796 KB Output is correct
35 Correct 62 ms 1216 KB Output is correct
36 Correct 62 ms 944 KB Output is correct
37 Correct 79 ms 960 KB Output is correct
38 Correct 70 ms 956 KB Output is correct
39 Correct 56 ms 1112 KB Output is correct
40 Correct 67 ms 940 KB Output is correct
41 Correct 74 ms 1120 KB Output is correct
42 Correct 52 ms 960 KB Output is correct
43 Correct 54 ms 1196 KB Output is correct
44 Correct 70 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 62 ms 968 KB Partially correct
2 Partially correct 71 ms 1112 KB Partially correct
3 Partially correct 86 ms 948 KB Partially correct
4 Partially correct 63 ms 956 KB Partially correct
5 Partially correct 57 ms 1108 KB Partially correct
6 Partially correct 72 ms 1376 KB Partially correct
7 Partially correct 63 ms 1228 KB Partially correct
8 Partially correct 50 ms 856 KB Partially correct
9 Partially correct 81 ms 712 KB Partially correct
10 Partially correct 47 ms 1112 KB Partially correct
11 Partially correct 79 ms 936 KB Partially correct
12 Partially correct 44 ms 1120 KB Partially correct
13 Incorrect 128 ms 1640 KB Wrong Answer [6]
14 Halted 0 ms 0 KB -