Submission #807455

# Submission time Handle Problem Language Result Execution time Memory
807455 2023-08-04T17:45:56 Z farhan132 Monster Game (JOI21_monster) C++17
100 / 100
100 ms 324 KB
#include "monster.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef int ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert

bool cmp(ll x, ll y){
    if(abs(x - y) == 1) return x > y;
    return x < y;
}

void print(vector < ll > x){
    for(auto u : x) cout << u << ' ';
    cout << '\n';
}

vector < ll > merge(vector < ll > a, vector < ll > b){
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    vector < ll > c;
    while(a.size() && b.size()){
        if(Query(a.back(), b.back()) == 0){
            c.pb(a.back());
            a.pop_back();
        }else{
            c.pb(b.back());
            b.pop_back();
        }
    }
    while(a.size()){
        c.pb(a.back());
        a.pop_back();
    }
    while(b.size()){
        c.pb(b.back());
        b.pop_back();
    }
    return c;
}

vector < ll > merge_sort(vector < ll > p){
    if(p.size() == 1) return p;
    vector < ll > x;
    vector < ll > y;
    for(ll i = 0; i < p.size()/2; i++){
        x.pb(p[i]);
    }
    for(ll i = p.size()/2; i < p.size(); i++){
        y.pb(p[i]);
    }
    x = merge_sort(x);
    y = merge_sort(y);
    p = merge(x, y);
    return p;
}

void rev(vector < ll > &v, ll l, ll r){
  ll m = (l + r) / 2;
  for(ll i = l; i <= m; i++) swap(v[i], v[r - (i - l)]);
  return;
}

vector < ll > gen(vector < ll > p){
  vector < ll > ans(p.size());
  for(ll i = 0; i < p.size(); i++){
    ans[p[i]] = i;
  }
  return ans;
}

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

  vector < ll > p(n);

  for(ll i = 0; i < n; i++) p[i] = i;

  p = merge_sort(p);

  vector < ll > cnt(n, 0);

  ll lmt = min(n, 10);

  for(ll i = 0; i < lmt; i++){
    for(ll j = 0; j < lmt; j++){
      if(i - j){
        if(Query(p[i], p[j])) cnt[i]++;
      }
    }
  }
  vector < ll > cands;
  for(ll i = 0; i < lmt; i++){
    if(cnt[i] == 1) cands.pb(i);
  }
  ll k = cands[0];
  if(cands.size() > 1){
    k = Query(p[cands[0]], p[cands[1]]);
    if(k == 1) k = cands[0];
    else k = cands[1];
  }

  rev(p, 0, k);

  while(k + 1 < n){
    ll c = k + 1;
    while(Query(p[k], p[c]) == 0) c++;
    rev(p, k + 1, c);
    k = c;
  }

  return gen(p);
}

Compilation message

monster.cpp: In function 'std::vector<int> merge_sort(std::vector<int>)':
monster.cpp:54:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(ll i = 0; i < p.size()/2; i++){
      |                   ~~^~~~~~~~~~~~
monster.cpp:57:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(ll i = p.size()/2; i < p.size(); i++){
      |                            ~~^~~~~~~~~~
monster.cpp: In function 'std::vector<int> gen(std::vector<int>)':
monster.cpp:74:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(ll i = 0; i < p.size(); i++){
      |                 ~~^~~~~~~~~~
# 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 228 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 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 7 ms 208 KB Output is correct
17 Correct 10 ms 304 KB Output is correct
18 Correct 13 ms 304 KB Output is correct
19 Correct 6 ms 304 KB Output is correct
20 Correct 12 ms 304 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 256 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 11 ms 208 KB Output is correct
27 Correct 0 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 9 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 228 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 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 7 ms 208 KB Output is correct
17 Correct 10 ms 304 KB Output is correct
18 Correct 13 ms 304 KB Output is correct
19 Correct 6 ms 304 KB Output is correct
20 Correct 12 ms 304 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 256 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 11 ms 208 KB Output is correct
27 Correct 0 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 9 ms 304 KB Output is correct
33 Correct 94 ms 300 KB Output is correct
34 Correct 55 ms 308 KB Output is correct
35 Correct 73 ms 312 KB Output is correct
36 Correct 70 ms 312 KB Output is correct
37 Correct 82 ms 312 KB Output is correct
38 Correct 61 ms 304 KB Output is correct
39 Correct 69 ms 308 KB Output is correct
40 Correct 50 ms 300 KB Output is correct
41 Correct 47 ms 320 KB Output is correct
42 Correct 39 ms 316 KB Output is correct
43 Correct 43 ms 304 KB Output is correct
44 Correct 40 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 208 KB Output is correct
2 Correct 78 ms 304 KB Output is correct
3 Correct 68 ms 308 KB Output is correct
4 Correct 92 ms 312 KB Output is correct
5 Correct 100 ms 320 KB Output is correct
6 Correct 68 ms 208 KB Output is correct
7 Correct 69 ms 316 KB Output is correct
8 Correct 84 ms 308 KB Output is correct
9 Correct 69 ms 308 KB Output is correct
10 Correct 79 ms 296 KB Output is correct
11 Correct 70 ms 304 KB Output is correct
12 Correct 59 ms 312 KB Output is correct
13 Correct 28 ms 324 KB Output is correct
14 Correct 71 ms 208 KB Output is correct
15 Correct 35 ms 208 KB Output is correct
16 Correct 35 ms 208 KB Output is correct
17 Correct 81 ms 208 KB Output is correct
18 Correct 54 ms 320 KB Output is correct