답안 #483696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483696 2021-10-31T18:54:12 Z gmyu 커다란 상품 (IOI17_prize) C++14
100 / 100
53 ms 10804 KB
/*
ID: USACO_template
LANG: C++
PROG: https://oj.uz/problem/view/IOI17_prize
*/
#include <iostream>  //cin , cout
#include <fstream>   //fin, fout
#include <stdio.h>   // scanf , pringf
#include <cstdio>
#include <algorithm> // sort , stuff
#include <stack>     // stacks
#include <queue>     // queues
#include <map>
#include <string>
#include <string.h>
#include <set>

using namespace std;

typedef pair<int, int>          pii;
typedef vector<int>             vi;     /// adjlist without weight
typedef vector<pii>             vii;    /// adjlist with weight
typedef vector<pair<int,pii>>   vpip;   /// edge with weight
typedef long long               ll;

#define mp  make_pair
#define ff  first
#define ss  second
#define pb  push_back
#define sz(x)   (int)(x).size()

const int MOD = 1e9+7;  // 998244353;
const int MX  = 2e5+5;   //
const ll  INF = 1e18;    //

#define MAXV 200007
#define MAXE 100007

const int xdir[4] = {1,0,-1,0}, ydir[4] = {0,1,0,-1}; /// 4 directions
struct NODE {
    int x, y;
    int val;
    int visited;
    bool operator< (NODE b) const { return (x == b.x) ? (y < b.y) : (x < b.x); }
};
struct EDGE {
    int from, to;
    ll weight;
    bool operator<(EDGE other) const { return weight < other.weight; }
};

bool debug=false;


/** since cnt(t) > cnt(t-1)^2 and cnt(1) = 1, number of prize is more than 1, 2^1, 2^2, 2^3, ...
 *  which means the sum of # of more expensive items is unique since the sum of all prize <t is less than cnt(t)
 *  make totMore = a[0] + a[1]
 *  then for i and j, if totMore[i] == totMore[j], then they are the same type
 *  we can divide and conquer to find the higher prize item (until totMore == 0)
 *  for each totMore, if a[0] on the left is the same the a[0] here, then there is no more expensive between those two
 */

#include "prize.h"
int ans=-1;
set<int> cnt[MAXV];
int leMore[MAXV];

bool divRcon(int l, int r) {
    if(l>r) return false;
    int m = (l+r)/2;
    vi a = ask(m);
    int totMore = a[0] + a[1];
    leMore[m] = a[0];
    if(totMore==0) {ans = m; return true;}

    auto it = cnt[totMore].insert(m).ff;
    if(it==cnt[totMore].begin()) {
        if(divRcon(l,m-1)) return true;
    } else if(leMore[*prev(it)] != leMore[*it]) {
        if(divRcon(l, m-1)) return true;
    }

    if(next(it)==cnt[totMore].end()) {
        if(divRcon(m+1,r)) return true;
    }else if(leMore[*next(it)] != leMore[*it]) {
        if(divRcon(m+1, r)) return true;
    }

    return false;
}
int find_best(int n) {
    divRcon(0,n-1);
    return ans;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9800 KB Output is correct
2 Correct 5 ms 9688 KB Output is correct
3 Correct 5 ms 9672 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9672 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9672 KB Output is correct
8 Correct 5 ms 9672 KB Output is correct
9 Correct 4 ms 9672 KB Output is correct
10 Correct 5 ms 9792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9688 KB Output is correct
2 Correct 6 ms 9688 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9696 KB Output is correct
5 Correct 5 ms 9672 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9680 KB Output is correct
8 Correct 7 ms 9676 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9720 KB Output is correct
11 Correct 7 ms 9800 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 7 ms 10100 KB Output is correct
14 Correct 7 ms 9672 KB Output is correct
15 Correct 12 ms 9800 KB Output is correct
16 Correct 35 ms 10452 KB Output is correct
17 Correct 7 ms 9672 KB Output is correct
18 Correct 52 ms 10560 KB Output is correct
19 Correct 5 ms 9676 KB Output is correct
20 Correct 15 ms 9804 KB Output is correct
21 Correct 22 ms 10044 KB Output is correct
22 Correct 7 ms 9672 KB Output is correct
23 Correct 5 ms 9672 KB Output is correct
24 Correct 6 ms 9680 KB Output is correct
25 Correct 14 ms 10192 KB Output is correct
26 Correct 25 ms 10092 KB Output is correct
27 Correct 5 ms 9684 KB Output is correct
28 Correct 21 ms 10512 KB Output is correct
29 Correct 31 ms 10380 KB Output is correct
30 Correct 48 ms 10576 KB Output is correct
31 Correct 5 ms 9680 KB Output is correct
32 Correct 8 ms 9920 KB Output is correct
33 Correct 4 ms 9672 KB Output is correct
34 Correct 17 ms 9932 KB Output is correct
35 Correct 6 ms 9864 KB Output is correct
36 Correct 15 ms 9804 KB Output is correct
37 Correct 6 ms 9672 KB Output is correct
38 Correct 5 ms 9672 KB Output is correct
39 Correct 21 ms 10064 KB Output is correct
40 Correct 44 ms 10556 KB Output is correct
41 Correct 29 ms 10176 KB Output is correct
42 Correct 25 ms 10188 KB Output is correct
43 Correct 14 ms 10136 KB Output is correct
44 Correct 23 ms 10052 KB Output is correct
45 Correct 19 ms 9860 KB Output is correct
46 Correct 5 ms 9672 KB Output is correct
47 Correct 21 ms 10056 KB Output is correct
48 Correct 44 ms 10316 KB Output is correct
49 Correct 8 ms 9672 KB Output is correct
50 Correct 24 ms 10664 KB Output is correct
51 Correct 18 ms 10060 KB Output is correct
52 Correct 5 ms 9672 KB Output is correct
53 Correct 6 ms 9804 KB Output is correct
54 Correct 25 ms 10056 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 44 ms 10560 KB Output is correct
57 Correct 38 ms 10364 KB Output is correct
58 Correct 37 ms 10304 KB Output is correct
59 Correct 30 ms 10188 KB Output is correct
60 Correct 31 ms 10176 KB Output is correct
61 Correct 6 ms 9792 KB Output is correct
62 Correct 6 ms 9688 KB Output is correct
63 Correct 6 ms 9808 KB Output is correct
64 Correct 6 ms 9676 KB Output is correct
65 Correct 6 ms 9680 KB Output is correct
66 Correct 8 ms 9672 KB Output is correct
67 Correct 5 ms 9680 KB Output is correct
68 Correct 5 ms 9688 KB Output is correct
69 Correct 5 ms 9684 KB Output is correct
70 Correct 5 ms 9672 KB Output is correct
71 Correct 50 ms 10624 KB Output is correct
72 Correct 9 ms 10220 KB Output is correct
73 Correct 47 ms 10604 KB Output is correct
74 Correct 53 ms 10616 KB Output is correct
75 Correct 6 ms 9800 KB Output is correct
76 Correct 39 ms 10804 KB Output is correct
77 Correct 47 ms 10568 KB Output is correct
78 Correct 11 ms 10056 KB Output is correct
79 Correct 27 ms 10552 KB Output is correct
80 Correct 40 ms 10740 KB Output is correct
81 Correct 49 ms 10544 KB Output is correct
82 Correct 49 ms 10564 KB Output is correct
83 Correct 6 ms 9800 KB Output is correct
84 Correct 40 ms 10804 KB Output is correct
85 Correct 52 ms 10552 KB Output is correct
86 Correct 11 ms 10048 KB Output is correct
87 Correct 7 ms 9944 KB Output is correct
88 Correct 9 ms 10056 KB Output is correct
89 Correct 11 ms 10056 KB Output is correct
90 Correct 8 ms 9800 KB Output is correct
91 Correct 9 ms 9928 KB Output is correct
92 Correct 5 ms 9672 KB Output is correct
93 Correct 8 ms 9928 KB Output is correct
94 Correct 9 ms 10040 KB Output is correct
95 Correct 7 ms 9964 KB Output is correct
96 Correct 6 ms 9944 KB Output is correct
97 Correct 4 ms 9672 KB Output is correct