QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#23367 | #1832. Crab's Cannon | ezoilearner | WA | 3ms | 3800kb | C++14 | 1.4kb | 2022-03-15 19:06:54 | 2022-04-30 02:56:07 |
Judging History
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]);
sort(a+1,a+n+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: 3800kb
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: -100
Wrong Answer
time: 3ms
memory: 3780kb
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 2 2 2 2 1 1 1 2 2 2 2 2 2 1 1 1 1 2 2
result:
wrong answer 3rd numbers differ - expected: '3', found: '2'