QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89789#21. GCD-sumzjy00010 2ms3476kbC++171.5kb2023-03-21 11:43:382023-03-21 11:43:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-21 11:43:42]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3476kb
  • [2023-03-21 11:43:38]
  • 提交

answer

#include<bits/stdc++.h>
#define int __int128
#define ldb long double
using namespace std;
typedef pair<int,int> PII;
inline int read(){
	int x=0,f=1;char ch;
	while(!isdigit(ch=getchar()))if(ch=='-')f=-f;
	do x=(x<<3)+(x<<1)+(ch^48);while(isdigit(ch=getchar()));
	return x*f;
}
int ptop,pstk[40];
inline void write(int x,char ch='\n'){
	if(!x){
        putchar('0'),putchar(ch);
        return;
	}
	if(x<0)putchar('-'),x=-x;
	while(x)pstk[ptop++]=x%10,x/=10;
	while(ptop)putchar(pstk[--ptop]+'0');
	putchar(ch);
}
const int N=1e6+5,INF=1e36;
int n,k,tot;
int a[N],b[N],c[N],s[N],g[N],ans[N];
inline int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
void MAIN(){
	n=read(),read(),k=read();
    for(int i=1;i<=n;++i)a[i]=read();
    sort(a+1,a+n+1);
    int m=0,q=0;
    for(int i=1;i<=n;++i)
        if(i>1&&a[i]==a[i-1])b[++m]=a[i];
        else c[++q]=a[i];
    n=q;
    for(int i=1;i<=n;++i)
        a[i]=c[i],
        g[i]=gcd(g[i-1],a[i]),
        s[i]=s[i-1]+a[i];
    for(int i=0;i<=k;++i)ans[i]=-INF;
    for(int l=1,r=0;l<=n;l=r+1){
        int mx=-INF;
        for(r=l;r<=n&&g[r]==g[l];++r);
        --r;
		for(int i=r+1;i<=n;++i)
			a[i]=gcd(a[i],g[l]),
			mx=max(mx,a[i]-c[i]);
		for(int i=r;i>=l;--i)
			ans[i]=s[n]-s[i]+mx,
			a[i]=gcd(a[i],g[l]),
			mx=max(mx,a[i]-c[i]);
    }
	for(int i=1;i<=m;++i)b[i]+=b[i-1];
	tot=-INF;
	if(k<=m)tot=s[n]+b[m]-b[k];
	for(int i=0;i<=m&&i<=k;++i)
		tot=max(tot,b[m]-b[i]+ans[k-i]);
	write(tot);
}
signed main(){
	for(int T=1;T--;MAIN());
    return 0;
}
/*

*/

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

7
18 30 10 23 1 3 13

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

100
268 467 21 173 158 287 36 446 36 340 311 283 58 77 464 119 460 198 405 331 214 331 255 157 418 319 354 289 330 64 11 484 186 129 130 368 370 468 292 180 427 76 87 156 13 379 268 170 3 15 263 52 296 242 7 296 376 148 221 270 218 131 326 198 399 132 270 55 299 444 134 222 278 486 409 72 38 193 359...

output:


result:


Subtask #4:

score: 0
Wrong Answer

Test #51:

score: 0
Wrong Answer
time: 2ms
memory: 3476kb

input:

1270
1 2 6 7 8 9 10 11 13 14 16 18 19 20 22 23 25 26 28 30 31 32 33 37 38 40 42 43 44 45 46 47 48 49 50 52 53 55 56 57 58 59 62 63 64 67 68 69 70 71 72 74 75 77 78 80 85 86 87 88 89 90 92 96 97 98 99 100 101 103 104 105 107 108 109 113 119 122 124 126 128 132 134 135 137 140 143 144 149 150 151 154 ...

output:

1272573

result:

wrong answer 1st lines differ - expected: '1', found: '1272573'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%