# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
685273 |
2023-01-23T20:39:19 Z |
Huseyn123 |
Money (IZhO17_money) |
C++17 |
|
123 ms |
36676 KB |
#include <bits/stdc++.h>
#define MAX 1000010
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,r,m,n2,m2,k,cnt=0,a[MAX],b[MAX],x,y,z,x2,y2,z2,res1=0;
ll c[501][501];
double db;
ll fact[MAX];
ll inv_fact[MAX];
//char c;
string str[MAX];
string s1,s2;
vector<tuple<ll,ll,ll>> v;
vector<pll> v1,v2;
const int mod = 998244353;
ll modmul(ll x,ll y,ll md){
if(y==1){
return x;
}
if(y%2){
return (x+modmul(x,y-1,md))%md;
}
else{
return (modmul((x+x)%md,y/2,md))%md;
}
}
ll powmod(ll x,ll y,ll md){
x%=md;
if(x==0){
return 0;
}
ll res=1;
while(y){
if(y%2==1){
//res=modmul(res,x,md);
res*=x;
res%=MOD;
y--;
}
else{
//x=modmul(x,x,md);
x*=x;
x%=MOD;
y/=2;
}
}
return res;
}
ll pow2(ll x,ll y){
if(x==0){
return 0;
}
ll res=1;
while(y>0){
if(y%2==1){
res*=x;
}
x*=x;
y/=2;
}
return res;
}
ll inv(ll n,ll md){
return powmod(n,md-2,md);
}
ll nCkm(ll n,ll k,ll md){
if(n-k<0){
return 0;
}
return fact[n]*inv_fact[k]%md*inv_fact[n-k]%md;
}
ll nCk(ll x,ll y){
if(x<y){
return 0;
}
ll res=1;
if(y>x-y){
for(int i=y+1;i<=x;i++){
res*=i;
}
for(int i=2;i<=x-y;i++){
res/=i;
}
}
else{
for(int i=x-y+1;i<=x;i++){
res*=i;
}
for(int i=2;i<=y;i++){
res/=i;
}
}
return res;
}
ll countbits(ll x){
ll cnt=0;
while(x){
cnt+=x&1;
x>>=1;
}
return cnt;
}
ll gcd(ll x,ll y){
if(y==0){
return x;
}
return gcd(y,x%y);
}
ll lcm(ll x,ll y){
return x*y/gcd(x,y);
}
bool alpha(char c1,char c2){
ll h1,h2;
if(c1>='a'){
h1=c1-'a';
}
else{
h1=c1-'A';
}
if(c2>='a'){
h2=c2-'a';
}
else{
h2=c2-'A';
}
if(h1==h2){
return c1<c2;
}
else{
return h1<h2;
}
}
ll dx[4]={0,0,1,1};
ll dy[4]={0,1,0,1};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
vector<vector<ll>> arr(21);
bool f(ll x){
for(auto mask:arr[x]){
vector<ll> c;
bool ok=false;
ll h=0;
for(int i=0;i<n;i++){
if(!ok){
auto it=c.begin();
h=0;
while(it!=c.end() && *it<=a[i]){
++it;
h++;
}
ok=true;
}
c.insert(c.begin()+h,a[i]);
h++;
if((mask&(1<<i))){
ok=false;
}
}
if(is_sorted(all(c))){
//cout << mask << "\n";
return true;
}
}
return false;
}
void solve(){
for(int i=0;i<(1<<n);i++){
if(!(i&(1<<(n-1)))){
continue;
}
ll h=countbits(i);
arr[h].pb(i);
}
ll l,r,mid;
l=1;
r=n;
while(l<r){
mid=(l+r)/2;
if(f(mid)){
r=mid;
}
else{
l=mid+1;
}
}
cout << r << "\n";
}
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
//cin >> t;
ll cnt1=1;
while(t--){
cin >> n;
inputar(a,n);
solve();
cnt1++;
}
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
ll b[51][51];
b[0][0] = 1;
for (int n = 1; n <= 50; ++n){
b[n][0] = b[n][n] = 1;
for (int k = 1; k < n; ++k)
b[n][k] = b[n - 1][k - 1] + b[n - 1][k];
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31528 KB |
Output is correct |
2 |
Correct |
16 ms |
31628 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31612 KB |
Output is correct |
5 |
Correct |
16 ms |
31596 KB |
Output is correct |
6 |
Correct |
17 ms |
31552 KB |
Output is correct |
7 |
Correct |
19 ms |
31612 KB |
Output is correct |
8 |
Correct |
16 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31572 KB |
Output is correct |
10 |
Correct |
20 ms |
31640 KB |
Output is correct |
11 |
Correct |
19 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31628 KB |
Output is correct |
13 |
Correct |
18 ms |
31624 KB |
Output is correct |
14 |
Correct |
17 ms |
31700 KB |
Output is correct |
15 |
Correct |
16 ms |
31572 KB |
Output is correct |
16 |
Correct |
17 ms |
31624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31528 KB |
Output is correct |
2 |
Correct |
16 ms |
31628 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31612 KB |
Output is correct |
5 |
Correct |
16 ms |
31596 KB |
Output is correct |
6 |
Correct |
17 ms |
31552 KB |
Output is correct |
7 |
Correct |
19 ms |
31612 KB |
Output is correct |
8 |
Correct |
16 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31572 KB |
Output is correct |
10 |
Correct |
20 ms |
31640 KB |
Output is correct |
11 |
Correct |
19 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31628 KB |
Output is correct |
13 |
Correct |
18 ms |
31624 KB |
Output is correct |
14 |
Correct |
17 ms |
31700 KB |
Output is correct |
15 |
Correct |
16 ms |
31572 KB |
Output is correct |
16 |
Correct |
17 ms |
31624 KB |
Output is correct |
17 |
Correct |
18 ms |
31700 KB |
Output is correct |
18 |
Correct |
18 ms |
31656 KB |
Output is correct |
19 |
Correct |
16 ms |
31644 KB |
Output is correct |
20 |
Correct |
96 ms |
36640 KB |
Output is correct |
21 |
Correct |
123 ms |
36636 KB |
Output is correct |
22 |
Correct |
32 ms |
36564 KB |
Output is correct |
23 |
Correct |
54 ms |
36648 KB |
Output is correct |
24 |
Correct |
120 ms |
36588 KB |
Output is correct |
25 |
Correct |
70 ms |
36648 KB |
Output is correct |
26 |
Correct |
85 ms |
36676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31528 KB |
Output is correct |
2 |
Correct |
16 ms |
31628 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31612 KB |
Output is correct |
5 |
Correct |
16 ms |
31596 KB |
Output is correct |
6 |
Correct |
17 ms |
31552 KB |
Output is correct |
7 |
Correct |
19 ms |
31612 KB |
Output is correct |
8 |
Correct |
16 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31572 KB |
Output is correct |
10 |
Correct |
20 ms |
31640 KB |
Output is correct |
11 |
Correct |
19 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31628 KB |
Output is correct |
13 |
Correct |
18 ms |
31624 KB |
Output is correct |
14 |
Correct |
17 ms |
31700 KB |
Output is correct |
15 |
Correct |
16 ms |
31572 KB |
Output is correct |
16 |
Correct |
17 ms |
31624 KB |
Output is correct |
17 |
Correct |
18 ms |
31700 KB |
Output is correct |
18 |
Correct |
18 ms |
31656 KB |
Output is correct |
19 |
Correct |
16 ms |
31644 KB |
Output is correct |
20 |
Correct |
96 ms |
36640 KB |
Output is correct |
21 |
Correct |
123 ms |
36636 KB |
Output is correct |
22 |
Correct |
32 ms |
36564 KB |
Output is correct |
23 |
Correct |
54 ms |
36648 KB |
Output is correct |
24 |
Correct |
120 ms |
36588 KB |
Output is correct |
25 |
Correct |
70 ms |
36648 KB |
Output is correct |
26 |
Correct |
85 ms |
36676 KB |
Output is correct |
27 |
Incorrect |
18 ms |
31612 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31528 KB |
Output is correct |
2 |
Correct |
16 ms |
31628 KB |
Output is correct |
3 |
Correct |
17 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31612 KB |
Output is correct |
5 |
Correct |
16 ms |
31596 KB |
Output is correct |
6 |
Correct |
17 ms |
31552 KB |
Output is correct |
7 |
Correct |
19 ms |
31612 KB |
Output is correct |
8 |
Correct |
16 ms |
31624 KB |
Output is correct |
9 |
Correct |
17 ms |
31572 KB |
Output is correct |
10 |
Correct |
20 ms |
31640 KB |
Output is correct |
11 |
Correct |
19 ms |
31572 KB |
Output is correct |
12 |
Correct |
17 ms |
31628 KB |
Output is correct |
13 |
Correct |
18 ms |
31624 KB |
Output is correct |
14 |
Correct |
17 ms |
31700 KB |
Output is correct |
15 |
Correct |
16 ms |
31572 KB |
Output is correct |
16 |
Correct |
17 ms |
31624 KB |
Output is correct |
17 |
Correct |
18 ms |
31700 KB |
Output is correct |
18 |
Correct |
18 ms |
31656 KB |
Output is correct |
19 |
Correct |
16 ms |
31644 KB |
Output is correct |
20 |
Correct |
96 ms |
36640 KB |
Output is correct |
21 |
Correct |
123 ms |
36636 KB |
Output is correct |
22 |
Correct |
32 ms |
36564 KB |
Output is correct |
23 |
Correct |
54 ms |
36648 KB |
Output is correct |
24 |
Correct |
120 ms |
36588 KB |
Output is correct |
25 |
Correct |
70 ms |
36648 KB |
Output is correct |
26 |
Correct |
85 ms |
36676 KB |
Output is correct |
27 |
Incorrect |
18 ms |
31612 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |