UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183176#3290. Mancala 游戏Richard1211100285ms8940kbC++116.8kb2023-08-08 10:12:472023-08-08 12:35:16

answer

//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
//#include <bits/extc++.h>
#else
//#include <ext/rope>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/hash_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
#endif
using namespace std;
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
const double pi=3.141592653589793238462643383279;
template<class T>inline T Min(register T a,register T b){
    return a<b?a:b;
}
template<class T>inline T Max(register T a,register T b){
    return a>b?a:b;
}
template<class T>inline bool Cmin(register T &a,register T b){
	return a>b?(a=b,true):false;
}
template<class T>inline bool Cmax(register T &a,register T b){
	return a<b?(a=b,true):false;
}
template<class T>inline T Abs(register T a){
    return a>0?a:-a;
}
template<class T>inline T Lowbit(register T x){
    return (x)&(-x);
}
template<class T>inline void Swap(register T &a,register T &b){
    b^=a^=b^=a;
}
template<class T>inline T Gcd(T a,T b){
    return b?Gcd(b,a%b):a;
}
template<class T>inline T Lcm(T a,T b){
    return a*b/Gcd(a,b);
}
template<class T>inline T Exgcd(T a,T b,T &x,T &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    T d=Exgcd(b,a%b,x,y);
    T t=x;
    x=y;
    y=t-a/b*y;
    return d;
}
template<class T>inline T ExExgcd(T a,T b,T &x,T &y,T c){
    if(b==0){
        x=c;
        y=0;
        return a;
    }
    T d=ExExgcd(b,a%b,x,y,c);
    T t=x;
    x=y;
    y=t-a/b*y;
    return d;
}
template<class T>inline T Ksc(T a,T b){
	if(a==0||b==0){
		return 0;
	}
	T ans=0;
	while(b){
		if(b&1){
			ans=a+ans;
		}
		a=a+a;
		b>>=1;
	}
	return ans;
}
template<class T>inline T Ksc(T a,T b,T p){
	if(a==0||b==0){
		return 0;
	}
	T ans=0;
	while(b){
		if(b&1){
			ans=(a+ans)%p;
		}
		a=(a+a)%p;
		b>>=1;
	}
	return ans;
}
template<class T>inline T Ksm(T a,T b,bool f=false){
	if(a==0){
		return 0;
	}
	if(b==0){
		return 1;
	}
    T ans=1;
    while(b){
        if(b&1){
            ans=!f?a*ans:Ksc(a,ans);
        }
        a=!f?a*a:Ksc(a,a);
        b>>=1;
    }
    return ans;
}
template<class T>inline T Ksm(T a,T b,T p,bool f=false){
	if(a==0){
		return 0;
	}
	if(b==0){
		return 1%p;
	}
    T ans=1;
    while(b){
        if(b&1){
            ans=!f?a*ans%p:Ksc(a,ans,p);
        }
        a=!f?a*a%p:Ksc(a,a,p);
        b>>=1;
    }
    return ans;
}
template<class T>inline T Inv(T x,T p){
	return Ksm(x,p-2,p);
}
template<class T>inline T Fac(T n){
    if(n==0){
        return 1;
    }
    long long ans=1;
    for(long long i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}
template<class T>inline T Fac(T n,T p){
    if(n==0){
        return 1;
    }
    long long ans=1;
    for(long long i=1;i<=n;i++){
        ans=ans*i%p;
    }
    return ans;
}
template<class T>inline long long Onenum(T x,bool f=true){
	return f?__builtin_popcountll(x):__builtin_popcount(x);
}
template<class T>inline long long Lowone(T x,bool f=true){
	return f?__builtin_ffsll(x):__builtin_ffs(x);
}
template<class T>inline long long Oneoddeven(T x,bool f=true){
	return f?__builtin_parityll(x):__builtin_parity(x);
}
template<class T>inline long long Prezero(T x,bool f=true){
	return f?__builtin_clzll(x):__builtin_clz(x);
}
template<class T>inline long long Sufzero(T x,bool f=true){
	return f?__builtin_ctzll(x):__builtin_ctz(x);
}
template<class T>inline bool Isdigit(T ch){
    return ch>='0' && ch<='9';
}
template<class T>inline bool Isletter(T ch){
    return ch>='A' && ch<='Z' || ch>='a' && ch<='z';
}
template<class T>inline void Memset(T *d,long long n,long long s){
    for(long long i=0;i<=s-1;i++){
        d[i]=n;
    }
}
template<class T>inline void debug(T s,string name){
    cout << name << ": " << s << endl;
}
template<class T>inline void bug(T s){
    cout << s << endl;
}
template<class T>inline T Sin(register T degree){
    return sin(degree*(pi/180));
}
template<class T>inline T Cos(register T degree){
    return cos(degree*(pi/180));
}
template<class T>inline T Tan(register T degree){
    return tan(degree*(pi/180));
}
template<class T>inline T Asin(register T degree){
    return asin(degree*(pi/180));
}
template<class T>inline T Acos(register T degree){
    return acos(degree*(pi/180));
}
template<class T>inline T Atan(register T degree){
    return atan(degree*(pi/180));
}
inline int rd(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=(x<<1)+(x<<3)+(ch-'0');
        ch=getchar();
    }
    return x*f;
}
inline long long read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=(x<<1)+(x<<3)+(ch-'0');
        ch=getchar();
    }
    return x*f;
}
inline unsigned long long Read(){
    unsigned long long x=0;
	long long f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=(x<<1)+(x<<3)+(ch-'0');
        ch=getchar();
    }
    return x*f;
}
inline bool wrt(int x,char ch='\n'){
	static char buf[64];
    static int len=-1;
    if(x<0){
        putchar('-');
        x=-x;
    }
    do{
        buf[++len]=x%10;
        x/=10;
    }
    while(x);
    while(len>=0){
        putchar(buf[len--]+'0');
    }
    putchar(ch);
    return true;
}
inline bool write(long long x,char ch='\n'){
    static char buf[64];
    static long long len=-1;
    if(x<0){
        putchar('-');
        x=-x;
    }
    do{
        buf[++len]=x%10;
        x/=10;
    }
    while(x);
    while(len>=0){
        putchar(buf[len--]+'0');
    }
    putchar(ch);
    return true;
}
inline bool Write(unsigned long long x,char ch='\n'){
	static char buf[64];
    static long long len=-1;
    if(x<0){
        putchar('-');
        x=-x;
    }
    do{
        buf[++len]=x%10;
        x/=10;
    }
    while(x);
    while(len>=0){
        putchar(buf[len--]+'0');
    }
    putchar(ch);
    return true;
}
inline void OF(string s){
    string IN=s+".in";
    string OUT=s+".out";
    freopen(IN.c_str(),"r",stdin);
    freopen(OUT.c_str(),"w",stdout);
}
inline void CF(string s){
    fclose(stdin);
    fclose(stdout);
}
const long long N=2000200;
long long n,sum,ans;
long long a[N];
int main(){
	n=read();
	for(register int i=1;i<=n;++i){
		a[i]=read();
		sum+=a[i];
	}
	for(register int i=n;i>=1;--i){
		a[i]<=i?ans+=(ans+a[i])/i:0;
	}
	return !write(Min(ans+1,sum));
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

4
0 1 100 4


output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 5
Accepted
time: 0ms
memory: 1128kb

input:

3
1 1 3

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 5
Accepted
time: 0ms
memory: 1128kb

input:

4
1 3 3 4

output:

6

result:

ok 1 number(s): "6"

Test #5:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

5
1 2 0 3 5

output:

10

result:

ok 1 number(s): "10"

Test #6:

score: 5
Accepted
time: 1ms
memory: 1124kb

input:

6
0 2 0 3 5 7

output:

9

result:

ok 1 number(s): "9"

Test #7:

score: 5
Accepted
time: 0ms
memory: 1128kb

input:

7
1 2 3 4 5 1 7

output:

18

result:

ok 1 number(s): "18"

Test #8:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

200
1 1 4 3 5 1 7 10 9 10 11 16 13 11 22 6 17 18 19 30 21 27 23 24 25 26 28 28 37 2 31 19 25 35 35 1...

output:

3162

result:

ok 1 number(s): "3162"

Test #9:

score: 5
Accepted
time: 1ms
memory: 1124kb

input:

250
0 2 1 4 5 6 7 12 9 10 11 12 17 8 15 16 14 18 19 20 15 7 7 4 25 26 30 28 29 30 31 37 33 34 48 36 ...

output:

6879

result:

ok 1 number(s): "6879"

Test #10:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

280
1 2 3 4 5 6 7 8 4 11 13 12 13 14 6 11 17 18 21 20 28 1 3 31 4 13 33 9 10 11 7 32 20 34 42 46 3 3...

output:

8100

result:

ok 1 number(s): "8100"

Test #11:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

290
0 3 3 6 5 6 7 0 5 10 9 12 13 14 15 24 22 18 11 20 21 4 23 11 34 26 28 15 29 30 12 32 5 34 44 12 ...

output:

4541

result:

ok 1 number(s): "4541"

Test #12:

score: 5
Accepted
time: 0ms
memory: 1128kb

input:

300
1 2 0 4 5 6 7 0 9 2 9 6 13 2 15 24 12 18 3 20 21 22 28 9 25 39 27 28 29 30 19 32 33 4 16 41 43 3...

output:

11338

result:

ok 1 number(s): "11338"

Test #13:

score: 5
Accepted
time: 0ms
memory: 1124kb

input:

300
1 2 4 4 3 6 7 8 9 10 1 17 0 20 15 16 17 10 3 26 24 31 7 15 9 26 8 28 33 42 31 41 33 34 35 18 37 ...

output:

6990

result:

ok 1 number(s): "6990"

Test #14:

score: 5
Accepted
time: 0ms
memory: 1136kb

input:

1800
0 3 3 1 7 9 7 8 9 10 2 0 13 14 18 16 17 18 19 27 21 8 23 24 25 26 27 28 29 30 31 32 33 36 35 37...

output:

130199

result:

ok 1 number(s): "130199"

Test #15:

score: 5
Accepted
time: 0ms
memory: 1136kb

input:

1900
0 2 3 4 5 3 2 5 9 10 4 12 13 14 15 6 17 18 19 23 25 1 23 24 25 27 27 3 7 30 31 32 33 34 12 54 3...

output:

307557

result:

ok 1 number(s): "307557"

Test #16:

score: 5
Accepted
time: 0ms
memory: 1140kb

input:

2000
1 1 3 3 5 7 7 8 9 0 11 12 13 14 15 8 21 2 20 20 21 21 23 24 23 26 10 2 14 6 31 29 33 34 38 36 3...

output:

286998

result:

ok 1 number(s): "286998"

Test #17:

score: 5
Accepted
time: 11ms
memory: 1904kb

input:

100000
1 2 4 4 5 6 8 8 9 10 2 8 13 21 18 16 20 18 19 20 21 22 11 27 18 26 27 28 29 30 31 0 38 34 35 ...

output:

262013086

result:

ok 1 number(s): "262013086"

Test #18:

score: 5
Accepted
time: 86ms
memory: 7372kb

input:

800000
1 0 3 4 5 6 7 7 9 1 11 12 14 14 19 16 8 18 12 20 21 15 16 11 25 34 30 40 29 30 14 32 1 23 10 ...

output:

17726464510

result:

ok 1 number(s): "17726464510"

Test #19:

score: 5
Accepted
time: 82ms
memory: 8152kb

input:

900000
1 2 3 5 5 1 7 8 9 15 8 6 13 14 8 16 17 6 9 3 21 29 23 24 25 10 22 10 10 8 33 32 33 17 28 29 1...

output:

19943656410

result:

ok 1 number(s): "19943656410"

Test #20:

score: 5
Accepted
time: 104ms
memory: 8940kb

input:

1000000
0 2 3 1 5 6 7 8 9 10 9 12 13 14 15 16 17 18 19 20 21 2 33 24 7 26 2 28 29 7 31 32 14 34 15 3...

output:

38517338601

result:

ok 1 number(s): "38517338601"