QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#23368#1832. Crab's CannonezoilearnerWA 3ms3804kbC++141.5kb2022-03-15 19:11:562022-04-30 02:56:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 02:56:10]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3804kb
  • [2022-03-15 19:11:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef pair<int,int> pii;
#define FR first
#define SE second

inline void rd(int &x){
	x=0;char ch=getchar();int f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	x*=f;
}


int n;ll L;
#define Maxn 300010

ll gcd(ll a,ll b){
	if(!b)return a;
	return gcd(b,a%b);
}

ll a[Maxn];
typedef pair<ll,ll> pll;
pll A[65];int cnt;

void run(int x){
	int pre=cnt;
	A[x-1].FR=A[x].FR;
	A[x-1].SE=gcd(A[x-1].SE,A[x].SE);
	rep(i,x,cnt-1)A[i]=A[i+1];cnt--;
}

int main(){
	while(~scanf("%d%lld",&n,&L)){
		if(n==0&&L==0)break;
		cnt=0;
		rep(i,1,n)scanf("%lld",&a[i]);a[++n]=1;
		sort(a+1,a+n+1);n=unique(a+1,a+n+1)-a-1;
		for(int i=1,lst;i<=n;i=lst+1){
			ll g=a[i]-a[i-1];
			lst=i;while(lst+1<=n&&a[lst]*2>a[lst+1]){
				lst++;
				g=gcd(g,a[lst]-a[lst-1]);
			}
			A[++cnt]=pll(a[lst],g);
		}
		while(true){
			bool fl=true;
			rep(i,1,cnt){
				if(A[i].SE<A[i-1].FR){
					run(i);
					fl=false;
					break;
				}
				if(A[i].FR%A[i].SE==0&&i>1&&A[i-1].FR%A[i-1].SE==0){
					run(i);
					fl=false;
					break;
				}
			}
			if(fl)break;
		}
		if(A[1].SE==2)A[1].SE=1;
		ll res=0;
		rep(i,1,cnt)res+=(A[i].FR-A[i-1].FR)/A[i].SE;
		printf("%lld\n",res);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3788kb

input:

3 7
1 3 7
4 12
7 1 3 9
3 16
16 1 8
0 0

output:

3
5
3

result:

ok 3 number(s): "3 5 3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3804kb

input:

2 1048576
1 1048576
2 1048576
1048576 1
2 1048576
51135 13546
2 1048576
13546 51135
2 1048576
1 51135
2 1048576
51135 1
1 1048576
1
1 1048576
1048576
1 1048576
51135
2 104857600000000000
1 104857600000000000
2 104857600000000000
104857600000000000 1
2 104857600000000000
5113500000000 13546
2 1048576...

output:

2
2
3
3
2
2
1
2
2
2
2
3
3
2
2
1
2
2
2
3
3

result:

ok 21 numbers

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3648kb

input:

5 96
7 12 61 37 93
4 100
63 2 16 35
5 88
7 43 70 23 8
4 29
22 7 5 14
1 2
2
2 3
2 3
0 0

output:

93
63
70
22
2
3

result:

wrong answer 2nd numbers differ - expected: '6', found: '63'