답안 #1112974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112974 2024-11-15T10:29:41 Z SalihSahin 커다란 상품 (IOI17_prize) C++14
20 / 100
172 ms 12376 KB
#include <bits/stdc++.h>
#define pb push_back
#include "prize.h"

using namespace std;
/*
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;

vector<int> ask(int i) {
   query_count++;
   if(query_count > max_q) {
      cerr << "Query limit exceeded" << endl;
      //cout<<query_count<<" babag "<<endl;
      exit(0);
   }

   if(i < 0 || i >= n) {
      cerr << "Bad index: " << i << endl;
      exit(0);
   }

   vector<int> res(2);
   res[0] = rank_count[g[i] - 1][i + 1];
   res[1] = rank_count[g[i] - 1][n] - res[0];
   return res;
}
*/
const int MAXN = 2e5 + 5;
vector<vector<int> > check(MAXN, vector<int>(2, -1));
vector<int> small(MAXN);

void f(int n, int smallcnt, int l, int r, int cnt){
   if(l == r){
      check[l] = ask(l);
      small[l] = 1;
      return;
   }
   int mid = (l + r)/2;
   int m = -1;

   for(int delt = 0; delt <= (r - l + 1)/2 + 1; delt++){
      if(mid + delt <= r){
         if(check[mid + delt][0] == -1) check[mid + delt] = ask(mid + delt);
         if(check[mid + delt][0] + check[mid + delt][1] == smallcnt){
            m = mid + delt;
            break;
         }
         else{
            small[mid + delt] = 1;
         }
      }

      if(mid - delt >= l){
         if(check[mid - delt][0] == -1) check[mid - delt] = ask(mid - delt);
         if(check[mid - delt][0] + check[mid - delt][1] == smallcnt){
            m = mid - delt;
            break;
         }
         else{
            small[mid - delt] = 1;
         }
      }
   }

   if(m == -1) return; // aralıktaki herkes small ve tagledik
   if(l > 0 && check[l-1][0] == -1) check[l-1] = ask(l-1);
   if(r < n-1 && check[r+1][0] == -1) check[r+1] = ask(r+1);

   int solcnt = check[m][0] - (l > 0 ? check[l-1][0] : 0);
   int sagcnt = check[m][1] - (r < n-1 ? check[r+1][1] : 0);
   if(l <= m-1 && solcnt > 0){
      //cout<<l<<" - "<<m-1<<" -> "<<solcnt<<endl;
      f(n, smallcnt, l, m-1, solcnt);
   }

   if(m+1 <= r && sagcnt > 0){
      //cout<<m+1<<" - "<<r<<" -> "<<sagcnt<<endl;
      f(n, smallcnt, m+1, r, sagcnt);
   }
}

long long kokbul(long long n){
   long long l = 1, r = n;
   while(l < r){
      long long m = (l + r)/2;

      if(m * m < n) l = m + 1;
      else r = m;
   }

   return l;
}

int find_best(int n) {
   int smallcnt = 0;
   int kok = kokbul(n) + 15;
   kok = min(kok, n);
   
   for(int i = 0; i < kok; i++){
      check[i] = ask(i);
      smallcnt = max(smallcnt, check[i][0] + check[i][1]);
   }
   for(int i = 0; i < kok; i++){
      if(check[i][0] + check[i][1] < smallcnt) small[i] = 1;
   }

   f(n, smallcnt, 0, n-1, smallcnt);
   int ans = -1;
   for(int i = 0; i < n; i++){
      if(small[i] == 1){
         if(check[i][0] == -1) check[i] = ask(i);
         if(check[i][0] + check[i][1] == 0){
            ans = i;
         }
      }
   }
   return ans;
}
/*
int main() {
   cin>>n;
   g.resize(n);

   for(int i = 0; i < n; i++) {
      cin>>g[i];
      if(g[i] < 1) {
         cerr << "Invalid rank " << g[i] << " at index " << i << endl;
         exit(0);
      }
   }

   int max_rank = *max_element(g.begin(), g.end());

   rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
   for(int r = 0; r <= max_rank; r++) {
      for(int i = 1; i <= n; i++) {
         rank_count[r][i] = rank_count[r][i - 1];
         if(g[i - 1] == r)
           rank_count[r][i]++;
      }
   }

   for(int i = 0; i <= n; i++)
      for(int r = 1; r <= max_rank; r++)
         rank_count[r][i] += rank_count[r - 1][i];

   int res = find_best(n);
   cout << res << endl << "Query count: " << query_count << endl;
   return 0;
}
*/
/*
int main() {
   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
   int t;
   cin>>t;
   while(t--){
      //cin>>n;
      //n = rng() % 55 + 7;
      n = 1e5;
      g.resize(n);

      for(int i = 0; i < n; i++){
         small[i] = 0;
         check[i][0] = check[i][1] = -1;
      }

      for(int i = 0; i < n; i++) {
         //cin>>g[i];
         g[i] = 2;
         if(g[i] < 1) {
            cerr << "Invalid rank " << g[i] << " at index " << i << endl;
            exit(0);
         }
      }
      int x = rng() % n;
      g[x] = 1;

      int max_rank = *max_element(g.begin(), g.end());

      rank_count.clear();
      rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
      for(int r = 0; r <= max_rank; r++) {
         for(int i = 1; i <= n; i++) {
            rank_count[r][i] = rank_count[r][i - 1];
            if(g[i - 1] == r)
              rank_count[r][i]++;
         }
      }

      for(int i = 0; i <= n; i++)
         for(int r = 1; r <= max_rank; r++)
            rank_count[r][i] += rank_count[r - 1][i];

      int res = find_best(n);
      if(res == -1){
         cout<<x<<" olması lazımdı "<<n<<" size array "<<endl;
         cout << res << endl << "Query count: " << query_count << endl;
      }
      cout<<x<<" olması lazımdı "<<n<<" size array "<<endl;
      cout << res << endl << "Query count: " << query_count << endl;
      query_count = 0;
   }

   return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12112 KB Output is correct
2 Correct 17 ms 12112 KB Output is correct
3 Correct 18 ms 12112 KB Output is correct
4 Correct 19 ms 12112 KB Output is correct
5 Correct 20 ms 12112 KB Output is correct
6 Correct 21 ms 12112 KB Output is correct
7 Correct 16 ms 12112 KB Output is correct
8 Correct 18 ms 12128 KB Output is correct
9 Correct 18 ms 12112 KB Output is correct
10 Correct 19 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 12184 KB Output is correct
2 Correct 18 ms 12112 KB Output is correct
3 Correct 20 ms 12368 KB Output is correct
4 Correct 27 ms 12196 KB Output is correct
5 Correct 24 ms 12128 KB Output is correct
6 Correct 19 ms 12112 KB Output is correct
7 Correct 23 ms 12112 KB Output is correct
8 Correct 18 ms 12368 KB Output is correct
9 Correct 19 ms 12176 KB Output is correct
10 Correct 18 ms 12112 KB Output is correct
11 Correct 26 ms 12112 KB Output is correct
12 Correct 20 ms 12112 KB Output is correct
13 Correct 24 ms 12112 KB Output is correct
14 Correct 30 ms 12112 KB Output is correct
15 Partially correct 110 ms 12280 KB Partially correct - number of queries: 5282
16 Partially correct 99 ms 12180 KB Partially correct - number of queries: 5530
17 Partially correct 109 ms 12184 KB Partially correct - number of queries: 5542
18 Partially correct 102 ms 12172 KB Partially correct - number of queries: 5531
19 Partially correct 100 ms 12176 KB Partially correct - number of queries: 5234
20 Correct 86 ms 12096 KB Output is correct
21 Partially correct 112 ms 12176 KB Partially correct - number of queries: 5496
22 Correct 85 ms 12112 KB Output is correct
23 Correct 21 ms 12280 KB Output is correct
24 Correct 28 ms 12112 KB Output is correct
25 Partially correct 113 ms 12128 KB Partially correct - number of queries: 5156
26 Partially correct 96 ms 12180 KB Partially correct - number of queries: 5132
27 Correct 19 ms 12112 KB Output is correct
28 Partially correct 100 ms 12112 KB Partially correct - number of queries: 5077
29 Correct 84 ms 12176 KB Output is correct
30 Partially correct 113 ms 12112 KB Partially correct - number of queries: 5493
31 Partially correct 103 ms 12112 KB Partially correct - number of queries: 5488
32 Correct 26 ms 12112 KB Output is correct
33 Correct 18 ms 12112 KB Output is correct
34 Partially correct 114 ms 12112 KB Partially correct - number of queries: 5518
35 Correct 20 ms 12112 KB Output is correct
36 Partially correct 119 ms 12112 KB Partially correct - number of queries: 5505
37 Correct 25 ms 12112 KB Output is correct
38 Correct 21 ms 12112 KB Output is correct
39 Partially correct 116 ms 12112 KB Partially correct - number of queries: 5502
40 Correct 86 ms 12112 KB Output is correct
41 Partially correct 108 ms 12112 KB Partially correct - number of queries: 5526
42 Partially correct 110 ms 12176 KB Partially correct - number of queries: 5526
43 Partially correct 98 ms 12112 KB Partially correct - number of queries: 5394
44 Partially correct 112 ms 12112 KB Partially correct - number of queries: 5530
45 Partially correct 97 ms 12172 KB Partially correct - number of queries: 5144
46 Partially correct 105 ms 12176 KB Partially correct - number of queries: 5538
47 Partially correct 104 ms 12376 KB Partially correct - number of queries: 5174
48 Partially correct 113 ms 12112 KB Partially correct - number of queries: 5527
49 Partially correct 100 ms 12176 KB Partially correct - number of queries: 5545
50 Partially correct 104 ms 12112 KB Partially correct - number of queries: 5543
51 Partially correct 96 ms 12112 KB Partially correct - number of queries: 5536
52 Partially correct 106 ms 12112 KB Partially correct - number of queries: 5528
53 Correct 19 ms 12020 KB Output is correct
54 Partially correct 103 ms 12112 KB Partially correct - number of queries: 5495
55 Partially correct 111 ms 12112 KB Partially correct - number of queries: 5526
56 Partially correct 107 ms 12112 KB Partially correct - number of queries: 5517
57 Partially correct 100 ms 12112 KB Partially correct - number of queries: 5501
58 Partially correct 116 ms 12176 KB Partially correct - number of queries: 5510
59 Partially correct 126 ms 12180 KB Partially correct - number of queries: 5532
60 Partially correct 94 ms 12112 KB Partially correct - number of queries: 5478
61 Correct 17 ms 12112 KB Output is correct
62 Correct 21 ms 12112 KB Output is correct
63 Correct 20 ms 12112 KB Output is correct
64 Correct 19 ms 12112 KB Output is correct
65 Correct 20 ms 12112 KB Output is correct
66 Correct 25 ms 12284 KB Output is correct
67 Correct 29 ms 12112 KB Output is correct
68 Correct 19 ms 12180 KB Output is correct
69 Correct 25 ms 12112 KB Output is correct
70 Correct 23 ms 12112 KB Output is correct
71 Partially correct 113 ms 12176 KB Partially correct - number of queries: 5221
72 Correct 29 ms 11956 KB Output is correct
73 Partially correct 108 ms 12112 KB Partially correct - number of queries: 5158
74 Partially correct 109 ms 12112 KB Partially correct - number of queries: 5185
75 Correct 25 ms 12124 KB Output is correct
76 Correct 90 ms 12180 KB Output is correct
77 Partially correct 105 ms 12176 KB Partially correct - number of queries: 5608
78 Correct 26 ms 12176 KB Output is correct
79 Correct 67 ms 12112 KB Output is correct
80 Partially correct 121 ms 12112 KB Partially correct - number of queries: 5548
81 Partially correct 109 ms 12112 KB Partially correct - number of queries: 5579
82 Partially correct 113 ms 12112 KB Partially correct - number of queries: 5526
83 Correct 20 ms 12368 KB Output is correct
84 Correct 105 ms 11956 KB Output is correct
85 Partially correct 119 ms 12176 KB Partially correct - number of queries: 5553
86 Incorrect 172 ms 12112 KB Incorrect
87 Halted 0 ms 0 KB -