Submission #3425501
Source Code Expand
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
h=true;
fact=vector<ll>(M);
fact[0]=fact[1]=1;
loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
ll out=1;
ll p=a%m;
while(b){
if(b&1)out=out*p%m;
p=p*p%m;
b>>=1;
}
return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
if(!h)init();
if(n<0||r<0||n<r)return 1;//??????
ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
return out;
}
int n;
vi in;
pii f(int l,int r,int a){
int mi=inf;
loop(i,l,r)mi=min(mi,in[i]);
vi t={l-1};
loop(i,l,r)if(in[i]==mi)t.pb(i);
t.pb(r);
vp in;
int w=r-l;
rep(i,t.size()-1)if(t[i]+1-t[i+1])in.pb(f(t[i]+1,t[i+1],mi)),w-=t[i+1]-t[i]-1;
int b=powmod(2,mi-a,MOD),c=powmod(2,w,MOD),d=(MOD+powmod(2,mi-a,MOD)-2)%MOD;
rep(i,in.size()){
(b*=in[i].first)%=MOD;
(c*=in[i].first+in[i].second)%=MOD;
(d*=in[i].first)%=MOD;
}
return {b,(c+d)%MOD};
}
signed main(){
init();
cin>>n;
in=vi(n);
rep(i,n)cin>>in[i];
pii a=f(0,n,0);
cout<<a.second<<endl;
}
Submission Info
Submission Time |
|
Task |
D - Histogram Coloring |
User |
ixmel_rd |
Language |
C++14 (GCC 5.4.1) |
Score |
1100 |
Code Size |
2824 Byte |
Status |
AC |
Exec Time |
11 ms |
Memory |
8064 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1100 / 1100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_0, example_1, example_2, example_3 |
All |
bigrand_0, bigrand_1, bigrand_2, bigrand_3, bigrand_4, bigrand_5, bigrand_6, bigrand_7, bigrand_8, bigrand_9, example_0, example_1, example_2, example_3, perm2_0, perm2_1, perm2_2, perm2_3, perm2_4, perm2_5, perm_0, perm_1, perm_2, perm_3, perm_4, perm_5, rand_0, rand_1, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9, smallc_0, smallc_1, smallc_2, smallc_3, smallc_4, smallc_5, smallc_6, smallc_7, smallc_8, smallc_9 |
Case Name |
Status |
Exec Time |
Memory |
bigrand_0 |
AC |
10 ms |
8064 KB |
bigrand_1 |
AC |
9 ms |
8064 KB |
bigrand_2 |
AC |
9 ms |
8064 KB |
bigrand_3 |
AC |
9 ms |
8064 KB |
bigrand_4 |
AC |
9 ms |
8064 KB |
bigrand_5 |
AC |
10 ms |
8064 KB |
bigrand_6 |
AC |
9 ms |
8064 KB |
bigrand_7 |
AC |
9 ms |
8064 KB |
bigrand_8 |
AC |
9 ms |
8064 KB |
bigrand_9 |
AC |
9 ms |
8064 KB |
example_0 |
AC |
9 ms |
8064 KB |
example_1 |
AC |
9 ms |
8064 KB |
example_2 |
AC |
10 ms |
8064 KB |
example_3 |
AC |
9 ms |
8064 KB |
perm2_0 |
AC |
9 ms |
8064 KB |
perm2_1 |
AC |
9 ms |
8064 KB |
perm2_2 |
AC |
10 ms |
8064 KB |
perm2_3 |
AC |
9 ms |
8064 KB |
perm2_4 |
AC |
10 ms |
8064 KB |
perm2_5 |
AC |
9 ms |
8064 KB |
perm_0 |
AC |
11 ms |
8064 KB |
perm_1 |
AC |
10 ms |
8064 KB |
perm_2 |
AC |
9 ms |
8064 KB |
perm_3 |
AC |
11 ms |
8064 KB |
perm_4 |
AC |
9 ms |
8064 KB |
perm_5 |
AC |
10 ms |
8064 KB |
rand_0 |
AC |
9 ms |
8064 KB |
rand_1 |
AC |
9 ms |
8064 KB |
rand_2 |
AC |
10 ms |
8064 KB |
rand_3 |
AC |
9 ms |
8064 KB |
rand_4 |
AC |
9 ms |
8064 KB |
rand_5 |
AC |
9 ms |
8064 KB |
rand_6 |
AC |
9 ms |
8064 KB |
rand_7 |
AC |
10 ms |
8064 KB |
rand_8 |
AC |
10 ms |
8064 KB |
rand_9 |
AC |
10 ms |
8064 KB |
smallc_0 |
AC |
9 ms |
8064 KB |
smallc_1 |
AC |
9 ms |
8064 KB |
smallc_2 |
AC |
9 ms |
8064 KB |
smallc_3 |
AC |
10 ms |
8064 KB |
smallc_4 |
AC |
9 ms |
8064 KB |
smallc_5 |
AC |
10 ms |
8064 KB |
smallc_6 |
AC |
9 ms |
8064 KB |
smallc_7 |
AC |
10 ms |
8064 KB |
smallc_8 |
AC |
10 ms |
8064 KB |
smallc_9 |
AC |
10 ms |
8064 KB |