답안 #213047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213047 2020-03-24T19:43:43 Z Nucleist 커다란 상품 (IOI17_prize) C++14
97.57 / 100
172 ms 1656 KB
#include "prize.h"
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<int>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int kal;
dos aski[200001];
map<ve,set<int>>yo;
map<int,ve>gg;
int ans=0;
bool vis[200001];
set<int>curi;
set<dos>koli;
int rod=0,belek=-1;
int find_best(int n)
{ 
    int county=0;
    rod=0;belek=n-1;
 
    for (int i = 0; i < min(n,475); ++i)
    {
        ve sal=ask(i);
        county++;
        int yol=sal[0]+sal[1];
        if(yol==0)return i;
        kal=max(kal,yol);
    }
    queue<pair<int,dos>>q;
    int low=475;
    int high=n-1;
    ve last=ask(n-1);
    county++;
    if(last[0]+last[1]==0)return n-1;
    int med=(low+high)/2;
    q.push({med,{low,high}});
    while(!q.empty())
    {
    //debug(county)
    auto u=q.front();
    q.pop();
    
    int index=u.first;
    int indexa=index;
    int l=u.second.first;
    int r=u.second.second;
    bool ki=true;

    for(auto it:koli)
    {
        if(l>=it.first && r<=it.second)
        {
            ki=false;break;
        }
    }
    if(ki)
    {
    if(vis[index] || (l>belek || r<rod))continue;
    vis[index]=1;
    ve k = ask(index);
    if(k[0]+k[1]==0)return index;
    county++;
    //if(index==3273)debug(1)
    vis[index]=1;
    gg[index]=k;
    yo[k].insert(index);
    bool ka=true,ka1=true;
    bool na=false;
    if(k[0]+k[1]==kal)na=true;
    if(yo.find(k)!=yo.end())
    {
        auto u=(*(yo[k].begin()));
        if(u>index)
        {
        ka1=false;
        koli.insert({index,u});
        }
        if(u<index)
        {
        ka=false;
        koli.insert({u,index});
        }
    }
    //if(index!=indexa)ka=true;
    /*while(kaka[0]+kaka[1]!=kal && indexa>l)
    {
        if(kaka[0]==0 && kaka[1]==0){
            debug(county);return indexa;
        }
        else
        {
            if(kaka[0]+kaka[1]==1)
            {
                if(kaka[0]==1){belek=min(belek,indexa-1);}
                else rod=max(rod,indexa+1);
            }
            for(auto it:gg)
            {
                if(it.first<indexa)
                {
                    auto cur=it.second;
                    yo[it.second].erase(it.first);
                    it.second[1]--;
                    yo[it.second].insert(it.first);
                }
            }
            curi.insert(indexa);
        }
        indexa--;
        if(!vis[indexa]){kaka=ask(indexa);vis[indexa]=1;county++;}
        else kaka=gg[indexa];
    }
 
    vis[indexa]=1;
    indexi=0,indexi1=0;
    for(auto it:curi)
    {
        if(it<indexa)indexi++;
        else indexi1++;
    }
    kaka[0]-=indexi;
    kaka[1]-=indexi1;
    gg[indexa]=kaka;
    yo[kaka].insert(indexa);
    if(yo.find(kaka)!=yo.end())
    {
        auto u=(*(yo[kaka].begin()));
        if(u<indexa)ka=false;
    }*/
    if(ka && !vis[(l+indexa)/2])q.push({(l+index)/2,{l,index}});
    if(ka1 && !vis[(index+r)/2])q.push({(index+r)/2,{index,r}});
    
    }
    }
    //debug(county)
    return 0;
}
//koua

Compilation message

prize.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
prize.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
prize.cpp: In function 'int find_best(int)':
prize.cpp:86:10: warning: variable 'na' set but not used [-Wunused-but-set-variable]
     bool na=false;
          ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 12 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 11 ms 384 KB Output is correct
8 Correct 12 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 384 KB Output is correct
2 Correct 8 ms 592 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 10 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 12 ms 384 KB Output is correct
9 Correct 7 ms 520 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 16 ms 640 KB Output is correct
12 Correct 20 ms 640 KB Output is correct
13 Correct 21 ms 632 KB Output is correct
14 Correct 22 ms 504 KB Output is correct
15 Correct 70 ms 1144 KB Output is correct
16 Correct 127 ms 1400 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 87 ms 1416 KB Output is correct
19 Correct 11 ms 384 KB Output is correct
20 Correct 81 ms 1016 KB Output is correct
21 Correct 128 ms 1400 KB Output is correct
22 Correct 25 ms 760 KB Output is correct
23 Correct 14 ms 504 KB Output is correct
24 Correct 15 ms 632 KB Output is correct
25 Correct 116 ms 1400 KB Output is correct
26 Correct 137 ms 1400 KB Output is correct
27 Correct 8 ms 632 KB Output is correct
28 Correct 112 ms 1272 KB Output is correct
29 Correct 80 ms 1144 KB Output is correct
30 Correct 107 ms 1400 KB Output is correct
31 Correct 9 ms 384 KB Output is correct
32 Correct 20 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 136 ms 1400 KB Output is correct
35 Correct 9 ms 668 KB Output is correct
36 Correct 128 ms 1400 KB Output is correct
37 Correct 20 ms 632 KB Output is correct
38 Correct 11 ms 504 KB Output is correct
39 Correct 168 ms 1528 KB Output is correct
40 Correct 103 ms 1272 KB Output is correct
41 Correct 108 ms 1564 KB Output is correct
42 Correct 143 ms 1400 KB Output is correct
43 Partially correct 142 ms 1528 KB Partially correct - number of queries: 5112
44 Correct 142 ms 1400 KB Output is correct
45 Correct 140 ms 1400 KB Output is correct
46 Correct 9 ms 384 KB Output is correct
47 Correct 117 ms 1272 KB Output is correct
48 Correct 119 ms 1400 KB Output is correct
49 Correct 127 ms 1400 KB Output is correct
50 Correct 154 ms 1400 KB Output is correct
51 Correct 141 ms 1528 KB Output is correct
52 Correct 150 ms 1400 KB Output is correct
53 Correct 14 ms 504 KB Output is correct
54 Correct 125 ms 1400 KB Output is correct
55 Correct 8 ms 384 KB Output is correct
56 Correct 151 ms 1400 KB Output is correct
57 Correct 98 ms 1416 KB Output is correct
58 Correct 128 ms 1400 KB Output is correct
59 Partially correct 166 ms 1528 KB Partially correct - number of queries: 5026
60 Correct 103 ms 1552 KB Output is correct
61 Correct 13 ms 504 KB Output is correct
62 Correct 8 ms 664 KB Output is correct
63 Correct 14 ms 504 KB Output is correct
64 Correct 14 ms 512 KB Output is correct
65 Correct 7 ms 416 KB Output is correct
66 Correct 12 ms 384 KB Output is correct
67 Correct 9 ms 384 KB Output is correct
68 Correct 11 ms 384 KB Output is correct
69 Correct 10 ms 384 KB Output is correct
70 Correct 10 ms 384 KB Output is correct
71 Partially correct 172 ms 1656 KB Partially correct - number of queries: 5243
72 Correct 19 ms 640 KB Output is correct
73 Partially correct 149 ms 1656 KB Partially correct - number of queries: 5180
74 Partially correct 149 ms 1656 KB Partially correct - number of queries: 5207
75 Correct 8 ms 544 KB Output is correct
76 Correct 138 ms 1528 KB Output is correct
77 Correct 140 ms 1400 KB Output is correct
78 Correct 15 ms 640 KB Output is correct
79 Correct 47 ms 1016 KB Output is correct
80 Correct 127 ms 1400 KB Output is correct
81 Correct 136 ms 1400 KB Output is correct
82 Correct 108 ms 1400 KB Output is correct
83 Correct 11 ms 512 KB Output is correct
84 Correct 92 ms 1272 KB Output is correct
85 Correct 128 ms 1400 KB Output is correct
86 Correct 12 ms 384 KB Output is correct
87 Correct 11 ms 384 KB Output is correct
88 Correct 10 ms 384 KB Output is correct
89 Correct 15 ms 384 KB Output is correct
90 Correct 12 ms 384 KB Output is correct
91 Correct 12 ms 384 KB Output is correct
92 Correct 12 ms 384 KB Output is correct
93 Correct 14 ms 640 KB Output is correct
94 Correct 18 ms 640 KB Output is correct
95 Correct 18 ms 632 KB Output is correct
96 Correct 19 ms 632 KB Output is correct
97 Correct 12 ms 384 KB Output is correct