Submission #112361

# Submission time Handle Problem Language Result Execution time Memory
112361 2019-05-19T05:27:49 Z shoemakerjo Minerals (JOI19_minerals) C++14
100 / 100
95 ms 3440 KB
#include "minerals.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int maxn = 100010;
// map<ll, int> v;

mt19937 mt_rand(time(NULL));

int cval;
const int magic = 2;


void go(vector<int>& a, vector<int>& b, bool aactive) {

  // cout << "as: ";
  // for (int vv : a) cout << vv << " ";
  // cout << endl;
  // cout << "bs: ";
  // for (int vv : b) cout << vv << " ";
  // cout << endl;

  if (a.size() == 2) {

    if (a[0] > b[0] || a[1] > b[1]) {
      Answer(a[0], b[1]);
      Answer(a[1], b[0]);
      return;
    }
    if (a[0] > b[1] || a[1] > b[0]) {
      Answer(a[0], b[0]);
      Answer(a[1], b[1]);
      return;
    }


    cval = Query(a[0]);
    int cur = Query(b[0]);
    if (aactive) {
      if (cval == cur) {
        Answer(a[0], b[1]);
        Answer(a[1], b[0]);
      }
      else {
        Answer(a[0], b[0]);
        Answer(a[1], b[1]);
      }
    }
    else {
      if (cval == cur) {
        Answer(a[0], b[0]);
        Answer(a[1], b[1]);
      }
      else {
        Answer(a[0], b[1]);
        Answer(a[1], b[0]);
      }
    }
    cval = cur;
    return;
  }

  vector<int> al, bl, ar, br;
  shuffle(a.begin(), a.end(), mt_rand);
  shuffle(b.begin(), b.end(), mt_rand);

  if (a.size() == 1 && b.size() == 1) {
    Answer(a[0], b[0]);
    return;
  }
  if (a.size() == 0) return;

  int mid = a.size()/2;
  for (int i = 0; i < magic; i++) {
    if (mid == 1) break;
    --mid;
  }
  //modify what is true for all less than this
  for (int i = 0; i < mid; i++) {
    cval = Query(a[i]);
    al.push_back(a[i]);
  }
  for (int i = mid; i < a.size(); i++) {
    ar.push_back(a[i]);
  }

  for (int i = 0; i < b.size(); i++) {
    // cout << "here: " << b[i] << endl;
    if (bl.size() == al.size()) {
      br.push_back(b[i]);
      continue;
    }
    if (br.size() == ar.size()) {
      bl.push_back(b[i]);
      continue;
    }

    int cur = Query(b[i]);
    if (cur != cval) {
      if (aactive) {
        bl.push_back(b[i]);
      }
      else {
        br.push_back(b[i]);
      }
    }
    else {
      if (aactive) {
        br.push_back(b[i]);
      }
      else {
        bl.push_back(b[i]);
      }
    }
    cval = cur;
  }

  go(al, bl, !aactive);
  go(ar, br, aactive);

}

void Solve(int N) {
  // int nrounds = 1000000/N;
  vector<int> cl, cr;
  cval = 0;
  vector<int> stuff;
  for (int i = 1; i <= 2*N; i++) {
    stuff.push_back(i);
  }
  shuffle(stuff.begin(), stuff.end(), mt_rand);
  //the above process saves about 2 queries (not worth)

  //beginning has more limitations we are not considering
  for (int i = 1; i <= 2*N; i++) {
    if (cl.size() == N) {
      cr.push_back(i);
      // mbig[i] = i-1;
      continue;
    }
    int cur = Query(i);
    if (cur != cval) {
      cl.push_back(i);
    }
    else cr.push_back(i);
    cval = cur;
  }
  go(cl, cr, true);
}

Compilation message

minerals.cpp: In function 'void go(std::vector<int>&, std::vector<int>&, bool)':
minerals.cpp:85:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = mid; i < a.size(); i++) {
                     ~~^~~~~~~~~~
minerals.cpp:89:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < b.size(); i++) {
                   ~~^~~~~~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:138:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (cl.size() == N) {
         ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 14 ms 784 KB Output is correct
5 Correct 27 ms 1216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
15 Correct 78 ms 2928 KB Output is correct
16 Correct 78 ms 2928 KB Output is correct
17 Correct 75 ms 2928 KB Output is correct
18 Correct 76 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
15 Correct 78 ms 2928 KB Output is correct
16 Correct 78 ms 2928 KB Output is correct
17 Correct 75 ms 2928 KB Output is correct
18 Correct 76 ms 2804 KB Output is correct
19 Correct 81 ms 2928 KB Output is correct
20 Correct 81 ms 3112 KB Output is correct
21 Correct 78 ms 2968 KB Output is correct
22 Correct 78 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
15 Correct 78 ms 2928 KB Output is correct
16 Correct 78 ms 2928 KB Output is correct
17 Correct 75 ms 2928 KB Output is correct
18 Correct 76 ms 2804 KB Output is correct
19 Correct 81 ms 2928 KB Output is correct
20 Correct 81 ms 3112 KB Output is correct
21 Correct 78 ms 2968 KB Output is correct
22 Correct 78 ms 2808 KB Output is correct
23 Correct 85 ms 3140 KB Output is correct
24 Correct 82 ms 2960 KB Output is correct
25 Correct 85 ms 3104 KB Output is correct
26 Correct 86 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
15 Correct 78 ms 2928 KB Output is correct
16 Correct 78 ms 2928 KB Output is correct
17 Correct 75 ms 2928 KB Output is correct
18 Correct 76 ms 2804 KB Output is correct
19 Correct 81 ms 2928 KB Output is correct
20 Correct 81 ms 3112 KB Output is correct
21 Correct 78 ms 2968 KB Output is correct
22 Correct 78 ms 2808 KB Output is correct
23 Correct 85 ms 3140 KB Output is correct
24 Correct 82 ms 2960 KB Output is correct
25 Correct 85 ms 3104 KB Output is correct
26 Correct 86 ms 2928 KB Output is correct
27 Correct 95 ms 3104 KB Output is correct
28 Correct 92 ms 3068 KB Output is correct
29 Correct 90 ms 3184 KB Output is correct
30 Correct 88 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
15 Correct 78 ms 2928 KB Output is correct
16 Correct 78 ms 2928 KB Output is correct
17 Correct 75 ms 2928 KB Output is correct
18 Correct 76 ms 2804 KB Output is correct
19 Correct 81 ms 2928 KB Output is correct
20 Correct 81 ms 3112 KB Output is correct
21 Correct 78 ms 2968 KB Output is correct
22 Correct 78 ms 2808 KB Output is correct
23 Correct 85 ms 3140 KB Output is correct
24 Correct 82 ms 2960 KB Output is correct
25 Correct 85 ms 3104 KB Output is correct
26 Correct 86 ms 2928 KB Output is correct
27 Correct 95 ms 3104 KB Output is correct
28 Correct 92 ms 3068 KB Output is correct
29 Correct 90 ms 3184 KB Output is correct
30 Correct 88 ms 2928 KB Output is correct
31 Correct 94 ms 3104 KB Output is correct
32 Correct 94 ms 3232 KB Output is correct
33 Correct 87 ms 3184 KB Output is correct
34 Correct 82 ms 3068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 14 ms 784 KB Output is correct
9 Correct 27 ms 1216 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 19 ms 1152 KB Output is correct
12 Correct 27 ms 1328 KB Output is correct
13 Correct 26 ms 1280 KB Output is correct
14 Correct 26 ms 1152 KB Output is correct
15 Correct 78 ms 2928 KB Output is correct
16 Correct 78 ms 2928 KB Output is correct
17 Correct 75 ms 2928 KB Output is correct
18 Correct 76 ms 2804 KB Output is correct
19 Correct 81 ms 2928 KB Output is correct
20 Correct 81 ms 3112 KB Output is correct
21 Correct 78 ms 2968 KB Output is correct
22 Correct 78 ms 2808 KB Output is correct
23 Correct 85 ms 3140 KB Output is correct
24 Correct 82 ms 2960 KB Output is correct
25 Correct 85 ms 3104 KB Output is correct
26 Correct 86 ms 2928 KB Output is correct
27 Correct 95 ms 3104 KB Output is correct
28 Correct 92 ms 3068 KB Output is correct
29 Correct 90 ms 3184 KB Output is correct
30 Correct 88 ms 2928 KB Output is correct
31 Correct 94 ms 3104 KB Output is correct
32 Correct 94 ms 3232 KB Output is correct
33 Correct 87 ms 3184 KB Output is correct
34 Correct 82 ms 3068 KB Output is correct
35 Correct 92 ms 3224 KB Output is correct
36 Correct 86 ms 3244 KB Output is correct
37 Correct 88 ms 3440 KB Output is correct
38 Correct 84 ms 3060 KB Output is correct