답안 #836326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836326 2023-08-24T10:14:31 Z Liudas Minerals (JOI19_minerals) C++17
85 / 100
47 ms 3824 KB
#include "minerals.h"
#include "minerals.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int last = 0;
void div(vector<int> start, vector<int> end, int par){
  int N = start.size();
  if(start.size() != end.size())
  cout << start.size() << " " << end.size() << endl;
  vector<int> l, r, le, re, left;
  if(N == 1){
    Answer(start[0], end[0]);
    return;
  }
  if(par == 1){
    for(int i = 0; i < N/2; i ++){
      last = Query(start[i]);
      l.push_back(start[i]);
    }
    for(int i = N/2; i < N; i ++){
      r.push_back(start[i]);
    }
    for(int i = 0; i < N; i ++){
      int t = Query(end[i]);
      if(t != last){
        last = t;
        le.push_back(end[i]);
        if(le.size() == (N+1)/2){
          for(int j = i + 1; j < N; j ++){
            left.push_back(end[j]);
          }
          break;
        }
      }
      else{
        re.push_back(end[i]);
        if(re.size() == (N+1)/2){
          for(int j = i + 1; j < N; j ++){
            left.push_back(end[j]);
          }
          break;
        }
      }
    }
    if(le.size() != (N+1)/2){
      if(le.size() < (N+3)/4){
        for(int i : le){
          Query(i);
        }
        for(int i : left){
          le.push_back(i);
        }
        div(le, l, 0);
      }
      else{
        for(int i : left){
          le.push_back(i);
          Query(i);
        }
        div(le, l, 1);
      }
    }
    else{
      div(le, l, 1);
    }
    if(re.size() != (N+1)/2){
      if(re.size() < (N + 3)/4){
        for(int i : re){
          Query(i);
        }
        for(int i : left){
          re.push_back(i);
        }
        div(r, re, 1);
      }
      else{
        for(int i : left){
          re.push_back(i);
          Query(i);
        }
        div(r, re, 2);
      }
    }
    else{
      div(r, re, 2);
    }
  }
  else if (par == 2){
    for(int i = 0; i < N/2; i ++){
      last = Query(start[i]);
      l.push_back(start[i]);
    }
    for(int i = N/2; i < N; i ++){
      r.push_back(start[i]);
    }
    for(int i = 0; i < N; i ++){
      int t = Query(end[i]);
      if(t != last){
        last = t;
        le.push_back(end[i]);
        if(le.size() == (N+1)/2){
          for(int j = i + 1; j < N; j ++){
            left.push_back(end[j]);
          }
          break;
        }
      }
      else{
        re.push_back(end[i]);
        if(re.size() == (N+1)/2){
          for(int j = i + 1; j < N; j ++){
            left.push_back(end[j]);
          }
          break;
        }
      }
    }
    if(le.size() != (N+1)/2){
      if(le.size() < (N+3)/4){
        for(int i : le){
          Query(i);
        }
        for(int i : left){
          le.push_back(i);
        }
        div(le, l, 1);
      }
      else{
        for(int i : left){
          le.push_back(i);
          Query(i);
        }
        div(l, le, 0);
      }
    }
    else{
      div(l, le, 0);
    }
    if(re.size() != (N+1)/2){
      if(re.size() < (N + 3)/4){
        for(int i : re){
          Query(i);
        }
        for(int i : left){
          re.push_back(i);
        }
        div(r, re, 2);
      }
      else{
        for(int i : left){
          re.push_back(i);
          Query(i);
        }
        div(r, re, 1);
      }
    }
    else{
      div(r, re, 1);
    }
  }
  if(par == 0){
    for(int i = 0; i < N/2; i ++){
      last = Query(start[i]);
      l.push_back(start[i]);
    }
    for(int i = N/2; i < N; i ++){
      r.push_back(start[i]);
    }
    for(int i = 0; i < N; i ++){
      int t = Query(end[i]);
      if(t == last){
        last = t;
        le.push_back(end[i]);
        if(le.size() == (N+1)/2){
          for(int j = i + 1; j < N; j ++){
            left.push_back(end[j]);
          }
          break;
        }
      }
      else{
        last = t;
        re.push_back(end[i]);
        if(re.size() == (N+1)/2){
          for(int j = i + 1; j < N; j ++){
            left.push_back(end[j]);
          }
          break;
        }
      }
    }
    if(le.size() != (N+1)/2){
      if(le.size() < (N+3)/4){
        for(int i : le){
          Query(i);
        }
        for(int i : left){
          le.push_back(i);
        }
        div(l, le, 1);
      }
      else{
        for(int i : left){
          le.push_back(i);
          Query(i);
        }
        div(l, le, 2);
      }
    }
    else{
      div(l, le, 2);
    }
    if(re.size() != (N+1)/2){
      if(re.size() < (N + 3)/4){
        for(int i : re){
          Query(i);
        }
        for(int i : left){
          re.push_back(i);
        }
        div(r, re, 0);
      }
      else{
        for(int i : left){
          re.push_back(i);
          Query(i);
        }
        div(re, r, 1);
      }
    }
    else{
      div(re, r, 1);
    }
  }
}
void Solve(int N) {
  vector<int> start, end;
  vector<int> order(2 * N);
  iota(order.begin(), order.end(), 0);
  shuffle(order.begin(), order.end(), mt19937(225));
  for(int i : order){
    int t = start.size();
    if(i < 0 || i >= N * 2){
      cout << i << " ..." << endl;
    }
    int ans = Query(i+1);
    if(ans == t + 1){
      start.push_back(i+1);
    }
    else{
      end.push_back(i+1);
    }
  }
  last = N;
  div(start, end, 2);
}

Compilation message

minerals.cpp: In function 'void div(std::vector<int>, std::vector<int>, int)':
minerals.cpp:33:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |         if(le.size() == (N+1)/2){
      |            ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:42:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |         if(re.size() == (N+1)/2){
      |            ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:50:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |     if(le.size() != (N+1)/2){
      |        ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:51:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |       if(le.size() < (N+3)/4){
      |          ~~~~~~~~~~^~~~~~~~~
minerals.cpp:71:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |     if(re.size() != (N+1)/2){
      |        ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:72:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |       if(re.size() < (N + 3)/4){
      |          ~~~~~~~~~~^~~~~~~~~~~
minerals.cpp:106:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |         if(le.size() == (N+1)/2){
      |            ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:115:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  115 |         if(re.size() == (N+1)/2){
      |            ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:123:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  123 |     if(le.size() != (N+1)/2){
      |        ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:124:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  124 |       if(le.size() < (N+3)/4){
      |          ~~~~~~~~~~^~~~~~~~~
minerals.cpp:144:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  144 |     if(re.size() != (N+1)/2){
      |        ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:145:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  145 |       if(re.size() < (N + 3)/4){
      |          ~~~~~~~~~~^~~~~~~~~~~
minerals.cpp:179:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  179 |         if(le.size() == (N+1)/2){
      |            ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:189:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  189 |         if(re.size() == (N+1)/2){
      |            ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:197:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  197 |     if(le.size() != (N+1)/2){
      |        ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:198:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  198 |       if(le.size() < (N+3)/4){
      |          ~~~~~~~~~~^~~~~~~~~
minerals.cpp:218:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  218 |     if(re.size() != (N+1)/2){
      |        ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:219:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  219 |       if(re.size() < (N + 3)/4){
      |          ~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 7 ms 908 KB Output is correct
5 Correct 12 ms 1464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 38 ms 3532 KB Output is correct
16 Correct 38 ms 3484 KB Output is correct
17 Correct 34 ms 3432 KB Output is correct
18 Correct 34 ms 3364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 38 ms 3532 KB Output is correct
16 Correct 38 ms 3484 KB Output is correct
17 Correct 34 ms 3432 KB Output is correct
18 Correct 34 ms 3364 KB Output is correct
19 Correct 35 ms 3520 KB Output is correct
20 Correct 39 ms 3524 KB Output is correct
21 Correct 35 ms 3488 KB Output is correct
22 Correct 35 ms 3444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 38 ms 3532 KB Output is correct
16 Correct 38 ms 3484 KB Output is correct
17 Correct 34 ms 3432 KB Output is correct
18 Correct 34 ms 3364 KB Output is correct
19 Correct 35 ms 3520 KB Output is correct
20 Correct 39 ms 3524 KB Output is correct
21 Correct 35 ms 3488 KB Output is correct
22 Correct 35 ms 3444 KB Output is correct
23 Correct 38 ms 3644 KB Output is correct
24 Correct 37 ms 3680 KB Output is correct
25 Correct 47 ms 3608 KB Output is correct
26 Correct 36 ms 3524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 38 ms 3532 KB Output is correct
16 Correct 38 ms 3484 KB Output is correct
17 Correct 34 ms 3432 KB Output is correct
18 Correct 34 ms 3364 KB Output is correct
19 Correct 35 ms 3520 KB Output is correct
20 Correct 39 ms 3524 KB Output is correct
21 Correct 35 ms 3488 KB Output is correct
22 Correct 35 ms 3444 KB Output is correct
23 Correct 38 ms 3644 KB Output is correct
24 Correct 37 ms 3680 KB Output is correct
25 Correct 47 ms 3608 KB Output is correct
26 Correct 36 ms 3524 KB Output is correct
27 Correct 37 ms 3660 KB Output is correct
28 Correct 37 ms 3748 KB Output is correct
29 Correct 38 ms 3656 KB Output is correct
30 Correct 37 ms 3580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 38 ms 3532 KB Output is correct
16 Correct 38 ms 3484 KB Output is correct
17 Correct 34 ms 3432 KB Output is correct
18 Correct 34 ms 3364 KB Output is correct
19 Correct 35 ms 3520 KB Output is correct
20 Correct 39 ms 3524 KB Output is correct
21 Correct 35 ms 3488 KB Output is correct
22 Correct 35 ms 3444 KB Output is correct
23 Correct 38 ms 3644 KB Output is correct
24 Correct 37 ms 3680 KB Output is correct
25 Correct 47 ms 3608 KB Output is correct
26 Correct 36 ms 3524 KB Output is correct
27 Correct 37 ms 3660 KB Output is correct
28 Correct 37 ms 3748 KB Output is correct
29 Correct 38 ms 3656 KB Output is correct
30 Correct 37 ms 3580 KB Output is correct
31 Incorrect 41 ms 3824 KB Wrong Answer [2]
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 7 ms 908 KB Output is correct
9 Correct 12 ms 1464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1104 KB Output is correct
12 Correct 13 ms 1568 KB Output is correct
13 Correct 12 ms 1524 KB Output is correct
14 Correct 12 ms 1464 KB Output is correct
15 Correct 38 ms 3532 KB Output is correct
16 Correct 38 ms 3484 KB Output is correct
17 Correct 34 ms 3432 KB Output is correct
18 Correct 34 ms 3364 KB Output is correct
19 Correct 35 ms 3520 KB Output is correct
20 Correct 39 ms 3524 KB Output is correct
21 Correct 35 ms 3488 KB Output is correct
22 Correct 35 ms 3444 KB Output is correct
23 Correct 38 ms 3644 KB Output is correct
24 Correct 37 ms 3680 KB Output is correct
25 Correct 47 ms 3608 KB Output is correct
26 Correct 36 ms 3524 KB Output is correct
27 Correct 37 ms 3660 KB Output is correct
28 Correct 37 ms 3748 KB Output is correct
29 Correct 38 ms 3656 KB Output is correct
30 Correct 37 ms 3580 KB Output is correct
31 Incorrect 41 ms 3824 KB Wrong Answer [2]
32 Halted 0 ms 0 KB -