QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90515 | #5252. Deforestation | HoMaMaOvO# | AC ✓ | 23ms | 16768kb | C++20 | 8.7kb | 2023-03-23 13:58:53 | 2023-03-23 13:58:56 |
Judging History
answer
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.a<<","<<p.b<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ";
dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif
using uint=unsigned;
using ull=unsigned long long;
template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
return os<<vc<t>(all(a));
}
template<int i,class T>
void print_tuple(ostream&,const T&){
}
template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
if(i)os<<",";
os<<get<i>(t);
print_tuple<i+1,T,Args...>(os,t);
}
template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
os<<"{";
print_tuple<0,tuple<Args...>,Args...>(os,t);
return os<<"}";
}
ll read(){
ll i;
cin>>i;
return i;
}
vi readvi(int n,int off=0){
vi v(n);
rep(i,n)v[i]=read()+off;
return v;
}
pi readpi(int off=0){
int a,b;cin>>a>>b;
return pi(a+off,b+off);
}
template<class t>
void print_single(t x,int suc=1){
cout<<x;
if(suc==1)
cout<<"\n";
if(suc==2)
cout<<" ";
}
template<class t,class u>
void print_single(const pair<t,u>&p,int suc=1){
print_single(p.a,2);
print_single(p.b,suc);
}
template<class T>
void print_single(const vector<T>&v,int suc=1){
rep(i,v.size())
print_single(v[i],i==int(v.size())-1?suc:2);
}
template<class T>
void print_offset(const vector<T>&v,ll off,int suc=1){
rep(i,v.size())
print_single(v[i]+off,i==int(v.size())-1?suc:2);
}
template<class T,size_t N>
void print_single(const array<T,N>&v,int suc=1){
rep(i,N)
print_single(v[i],i==int(N)-1?suc:2);
}
template<class T>
void print(const T&t){
print_single(t);
}
template<class T,class ...Args>
void print(const T&t,const Args&...args){
print_single(t,2);
print(args...);
}
string readString(){
string s;
cin>>s;
return s;
}
template<class T>
T sq(const T& t){
return t*t;
}
void YES(bool ex=true){
cout<<"YES\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void NO(bool ex=true){
cout<<"NO\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void Yes(bool ex=true){
cout<<"Yes\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void No(bool ex=true){
cout<<"No\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
//#define CAPITAL
/*
void yes(bool ex=true){
#ifdef CAPITAL
cout<<"YES"<<"\n";
#else
cout<<"Yes"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void no(bool ex=true){
#ifdef CAPITAL
cout<<"NO"<<"\n";
#else
cout<<"No"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}*/
void possible(bool ex=true){
#ifdef CAPITAL
cout<<"POSSIBLE"<<"\n";
#else
cout<<"Possible"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void impossible(bool ex=true){
#ifdef CAPITAL
cout<<"IMPOSSIBLE"<<"\n";
#else
cout<<"Impossible"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
constexpr ll ten(int n){
return n==0?1:ten(n-1)*10;
}
const ll infLL=LLONG_MAX/3;
#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif
int topbit(signed t){
return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
return t==0?-1:63-__builtin_clzll(t);
}
int topbit(ull t){
return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
return a==0?64:__builtin_ctzll(a);
}
int botbit(ull a){
return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
return __builtin_popcount(t);
}
int popcount(ll t){
return __builtin_popcountll(t);
}
int popcount(ull t){
return __builtin_popcountll(t);
}
bool ispow2(int i){
return i&&(i&-i)==i;
}
ll mask(int i){
return (ll(1)<<i)-1;
}
ull umask(int i){
return (ull(1)<<i)-1;
}
ll minp2(ll n){
if(n<=1)return 1;
else return ll(1)<<(topbit(n-1)+1);
}
bool inc(int a,int b,int c){
return a<=b&&b<=c;
}
template<class t> void mkuni(vc<t>&v){
sort(all(v));
v.erase(unique(all(v)),v.ed);
}
ll rand_int(ll l, ll r) { //[l, r]
//#ifdef LOCAL
static mt19937_64 gen;
/*#else
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif*/
return uniform_int_distribution<ll>(l, r)(gen);
}
ll rand_int(ll k){ //[0,k)
return rand_int(0,k-1);
}
template<class t>
void myshuffle(vc<t>&a){
rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}
template<class t>
int lwb(const vc<t>&v,const t&a){
return lower_bound(all(v),a)-v.bg;
}
template<class t>
bool bis(const vc<t>&v,const t&a){
return binary_search(all(v),a);
}
vvc<int> readGraph(int n,int m){
vvc<int> g(n);
rep(i,m){
int a,b;
cin>>a>>b;
//sc.read(a,b);
a--;b--;
g[a].pb(b);
g[b].pb(a);
}
return g;
}
vvc<int> readTree(int n){
return readGraph(n,n-1);
}
vc<ll> presum(const vi&a){
vc<ll> s(si(a)+1);
rep(i,si(a))s[i+1]=s[i]+a[i];
return s;
}
//BIT で数列を管理するときに使う (CF850C)
template<class t>
vc<t> predif(vc<t> a){
gnr(i,1,si(a))a[i]-=a[i-1];
return a;
}
template<class t>
vvc<ll> imos(const vvc<t>&a){
int n=si(a),m=si(a[0]);
vvc<ll> b(n+1,vc<ll>(m+1));
rep(i,n)rep(j,m)
b[i+1][j+1]=b[i+1][j]+b[i][j+1]-b[i][j]+a[i][j];
return b;
}
//verify してないや
void transvvc(int&n,int&m){
swap(n,m);
}
template<class t,class... Args>
void transvvc(int&n,int&m,vvc<t>&a,Args&...args){
assert(si(a)==n);
vvc<t> b(m,vi(n));
rep(i,n){
assert(si(a[i])==m);
rep(j,m)b[j][i]=a[i][j];
}
a.swap(b);
transvvc(n,m,args...);
}
//CF854E
void rotvvc(int&n,int&m){
swap(n,m);
}
template<class t,class... Args>
void rotvvc(int&n,int&m,vvc<t>&a,Args&...args){
assert(si(a)==n);
vvc<t> b(m,vi(n));
rep(i,n){
assert(si(a[i])==m);
rep(j,m)b[m-1-j][i]=a[i][j];
}
a.swap(b);
rotvvc(n,m,args...);
}
//ソートして i 番目が idx[i]
//CF850C
template<class t>
vi sortidx(const vc<t>&a){
int n=si(a);
vi idx(n);iota(all(idx),0);
sort(all(idx),[&](int i,int j){return a[i]<a[j];});
return idx;
}
//vs[i]=a[idx[i]]
//例えば sortidx で得た idx を使えば単にソート列になって返ってくる
//CF850C
template<class t>
vc<t> a_idx(const vc<t>&a,const vi&idx){
int n=si(a);
assert(si(idx)==n);
vc<t> vs(n);
rep(i,n)vs[i]=a[idx[i]];
return vs;
}
//CF850C
vi invperm(const vi&p){
int n=si(p);
vi q(n);
rep(i,n)q[p[i]]=i;
return q;
}
template<class t,class s=t>
s SUM(const vc<t>&a){
return accumulate(all(a),s(0));
}
template<class t>
t MAX(const vc<t>&a){
return *max_element(all(a));
}
template<class t>
t MIN(const vc<t>&a){
return *min_element(all(a));
}
template<class t,class u>
pair<t,u> operator+(const pair<t,u>&a,const pair<t,u>&b){
return mp(a.a+b.a,a.b+b.b);
}
vi vid(int n){
vi res(n);iota(all(res),0);
return res;
}
void slv(){
int w;cin>>w;
int ans=0;
auto dfs=[&](auto self)->int{
int add,c;cin>>add>>c;
vi ls;
rep(_,c){
int len=self(self);
int p=len/w,q=len%w;
ans+=p;
ls.pb(q);
}
sort(all(ls));
int sum=0;
for(auto v:ls){
if(sum+v<=w){
sum+=v;
}else{
ans++;
}
}
return sum+add;
};
int rem=dfs(dfs);
ans+=(rem+w-1)/w;
print(ans);
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
//int t;cin>>t;rep(_,t)
slv();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 3496kb
input:
999900000 7339 3 14947 2 12850 3 8986 10 11599 9 8889 10 10711 4 8015 1 11626 0 9492 1 7017 0 8863 0 8632 0 5321 5 9906 0 11687 0 9845 0 10469 0 11708 0 14950 5 11934 0 11922 0 13101 0 12000 0 9082 0 9273 5 12296 0 6119 0 9201 0 12652 0 12957 0 7454 5 12515 0 12976 0 10358 0 13997 0 8371 0 10181 5 8...
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 15ms
memory: 4116kb
input:
2 1 99999 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 ...
output:
99999
result:
ok single line: '99999'
Test #3:
score: 0
Accepted
time: 20ms
memory: 11692kb
input:
7 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10000 0 10000 2 10...
output:
142862500
result:
ok single line: '142862500'
Test #4:
score: 0
Accepted
time: 23ms
memory: 16768kb
input:
2 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10000 1 10...
output:
500000000
result:
ok single line: '500000000'
Test #5:
score: 0
Accepted
time: 19ms
memory: 3376kb
input:
9717 14907 2 6953 2 10004 2 10949 2 11766 2 14015 2 5640 2 10370 2 6432 2 7602 2 10238 2 9755 2 5788 2 10885 2 11858 2 9182 2 14174 0 12614 0 12080 1 12497 0 7708 2 9108 1 14948 0 9107 1 13540 0 7400 2 6303 2 14462 1 8021 0 7659 1 7232 0 14314 2 9495 1 8459 0 13069 1 5777 0 12734 2 7061 2 12810 2 13...
output:
105756
result:
ok single line: '105756'
Test #6:
score: 0
Accepted
time: 19ms
memory: 3492kb
input:
39375 7550 2 13825 2 11034 2 7836 2 11683 2 9571 2 13888 2 11680 2 5713 2 13175 2 11057 2 7849 2 5598 2 9557 2 7974 2 13285 2 8251 0 13513 0 6254 1 11361 0 13651 2 6286 1 10397 0 5450 1 9590 0 12571 2 7519 2 5512 1 5430 0 9148 1 5281 0 6991 2 6310 1 12868 0 13487 1 6045 0 12298 2 10198 2 11601 2 127...
output:
29976
result:
ok single line: '29976'
Test #7:
score: 0
Accepted
time: 16ms
memory: 3436kb
input:
874898 10304 7 7634 3 7362 9 7960 8 12298 2 5668 1 11762 4 14379 4 6126 1 8135 0 12246 1 13096 0 10376 1 14935 0 9311 0 6256 5 14752 1 12903 0 9645 1 5986 0 14329 0 8683 0 6501 0 6337 1 14416 5 11161 1 10643 0 8900 0 13527 0 9644 0 11961 0 13251 4 9559 1 5799 0 7021 1 13442 0 12589 0 8301 0 5765 7 1...
output:
2116
result:
ok single line: '2116'
Test #8:
score: 0
Accepted
time: 19ms
memory: 3372kb
input:
907686 6329 4 11400 6 5913 8 6890 1 6329 9 10018 5 5234 4 14656 2 11517 0 7330 0 6160 1 11296 1 8221 0 14502 2 14628 0 11846 0 11999 1 5458 0 9845 7 14799 1 9492 0 5534 1 8513 0 12919 1 11676 0 7286 1 8698 0 11372 0 13707 0 12517 0 12094 4 11587 2 5442 0 12160 0 10344 2 13437 0 12069 0 13431 1 9757 ...
output:
2108
result:
ok single line: '2108'
Test #9:
score: 0
Accepted
time: 11ms
memory: 3440kb
input:
19439 9535 1 14066 1 13123 8 14498 10 12761 10 13889 3 5303 4 6155 5 8591 1 9992 0 6323 1 5747 0 12132 1 12189 0 9518 1 11132 0 12872 1 5985 0 12140 1 7932 4 6628 1 9177 0 9398 1 7981 0 7774 1 9833 0 7483 1 12017 0 6505 4 8924 2 8786 0 5604 0 7191 1 14168 0 11672 1 13618 0 8420 1 7884 0 5693 4 12159...
output:
64996
result:
ok single line: '64996'
Extra Test:
score: 0
Extra Test Passed