Submission #138533
Source Code Expand
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<complex>
#include<map>
#include<set>
#include<bitset>
#include<iostream>
#include<sstream>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n-1; i >= 0; i--)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y);
#define mins(x,y) x = min(x,y);
#define pb push_back
#define sz(x) (int)(x).size()
#define popcount __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
const int MX = 2100, INF = 2000000000;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-10;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1}; //<^>v
int a[MX];
int t[MX];
int u[MX];
int l[MX];
int main(){
int n;
scanf("%d",&n);
rep(i,n) scanf("%d",&a[i]);
for(int si = n; si <= 512; si++){
rep(i,MX) t[i] = INF;
rep(i,MX) u[i] = 0;
rrep(i,si) t[i] = -1;
int c = si;
bool ok = true;
for(int i = n-1; i >= 0; i--){
t[c] = a[i]; if(a[i] < MX) u[a[i]] = 1;
if(t[c] >= t[c<<1] || t[c] >= t[c<<1|1]) ok = false;
c--;
}
rep(i,MX) l[i] = t[i];
vector<int> p;
for(int i = c; i >= 1; i--){
l[i] = min(l[i<<1],l[i<<1|1])-1;
p.pb(l[i]);
}
sort(rng(p));
//rep(i,sz(p)) printf("%d ",p[i]); puts("");
int e = 0;
rep(i,555){
if(e >= sz(p)) break;
if(u[i]) continue;
if(p[e] < i){
ok = false;
}
e++;
}
//if(si > 10) break;
if(ok){
printf("%d\n",si);
return 0;
}
}
puts("-1");
return 0;
}
Submission Info
Submission Time
2014-03-02 16:12:18+0900
Task
D - 壊れかけのヒープ
User
snuke
Language
C++ (G++ 4.6.4)
Score
100
Code Size
2021 Byte
Status
AC
Exec Time
30 ms
Memory
924 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:48:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:49:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
Judge Result
Set Name
All
Score / Max Score
100 / 100
Status
Set Name
Test Cases
All
hard-01, hard-02, hard-03, hard-04, hard-05, hard-06, hard-07, hard-08, hard-09, hard-10, hard-11, hard-12, hard-corner-01, hard-corner-02, hard-corner-03, hard-corner-04, hard-corner-05, hard-random-01, hard-random-02, hard-random-03, hard-random-04, hard-random-05, hard-random-06, hard-semirandom-01, hard-semirandom-02, hard-semirandom-03, hard-semirandom-04, hard-semirandom-05, hard-semirandom-06
Case Name
Status
Exec Time
Memory
hard-01
AC
21 ms
916 KB
hard-02
AC
22 ms
912 KB
hard-03
AC
22 ms
924 KB
hard-04
AC
25 ms
812 KB
hard-05
AC
23 ms
796 KB
hard-06
AC
20 ms
912 KB
hard-07
AC
29 ms
916 KB
hard-08
AC
27 ms
808 KB
hard-09
AC
28 ms
920 KB
hard-10
AC
23 ms
916 KB
hard-11
AC
29 ms
804 KB
hard-12
AC
30 ms
792 KB
hard-corner-01
AC
22 ms
920 KB
hard-corner-02
AC
23 ms
920 KB
hard-corner-03
AC
22 ms
924 KB
hard-corner-04
AC
22 ms
916 KB
hard-corner-05
AC
21 ms
912 KB
hard-random-01
AC
22 ms
920 KB
hard-random-02
AC
21 ms
912 KB
hard-random-03
AC
21 ms
920 KB
hard-random-04
AC
24 ms
912 KB
hard-random-05
AC
23 ms
920 KB
hard-random-06
AC
20 ms
916 KB
hard-semirandom-01
AC
22 ms
808 KB
hard-semirandom-02
AC
22 ms
924 KB
hard-semirandom-03
AC
24 ms
800 KB
hard-semirandom-04
AC
23 ms
916 KB
hard-semirandom-05
AC
23 ms
924 KB
hard-semirandom-06
AC
25 ms
800 KB
sample-01
AC
22 ms
804 KB
sample-02
AC
28 ms
912 KB
sample-03
AC
21 ms
924 KB
sample-04
AC
20 ms
920 KB