QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87879#21. GCD-sumReanap0 2ms3448kbC++143.7kb2023-03-14 17:43:092023-03-14 17:43:10

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-14 17:43:10]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3448kb
  • [2023-03-14 17:43:09]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
template <typename T>
void read(T &x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9') {x=(x<<3)+(x<<1)+(s^'0');s=getchar();}
	x *= f;
}
long long n, x;
int k;
const long long MAXEL=1000LL*1000LL*1000LL*1000LL;
std::vector<long long> li, result;
std::vector<std::pair<long long, int> > kro;
long long nwd(long long a, long long b)
{
    while (a != 0) {
        b %= a;
        std::swap(a, b);
    }
    return b;
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    read(n);
    result.resize(n+2);
    for (int i = 0; i < n; i++) {
        read(x);
        li.emplace_back(x);
    }
    sort(li.begin(), li.end());
    int ile = 0;
    long long last = li.front();
    for (auto l : li) {
        if (l == last) {
            ile++;
        } else {
            kro.emplace_back(last, ile);
            ile = 1;
            last = l;
        }
    }
    kro.emplace_back(last, ile);
    long long nw = 0;
    long long sum = 0;
    for (auto x : kro)
        sum += x.first;
    for (std::size_t i = 0; i < kro.size(); i++) {
        long long tmp = nwd(nw, kro[i].first);
        //std::cout<<i<<" tmp nw "<<tmp<<" "<<nw<<std::endl;
        if (tmp != nw) {
            long long max = -MAXEL; 
            for (std::size_t j = i; j < kro.size(); j++) 
                max = std::max(max, nwd(nw,kro[j].first ) - kro[j].first);
            long long sum2 = sum + max;
            //std::cout<<"m n "<<max<<" "<<nw<<" "<<sum<<std::endl;
            result[kro.size()-i] = std::max(result[kro.size()-i] ,sum2);
            
            result[kro.size()-i+1] = std::max(result[kro.size()-i+1] ,sum2-max+nw);
            
            //std::cout<<"$result["<<kro.size()-i<<"]= "<<result[kro.size()-i]<<std::endl;
            //std::cout<<"$result["<<kro.size()-i+1<<"]= "<<result[kro.size()-i+1]<<std::endl;
            int ite = 0;
            int poz = kro.size() - 1;
            std::vector<long long> str;
            while (true) {
                while (poz >= int(i) && kro[poz].second == 1)
                    poz--;
                if (poz < int(i))
                    break;
                kro[poz].second--;
                str.emplace_back(poz);
                ite++;
                sum2 += kro[poz].first;
                result[kro.size()-i+ite] = std::max(result[kro.size()-i+ite],sum2);
                result[kro.size()-i+ite+1] = std::max(result[kro.size()-i+ite+1],sum2-max+nw);
                //std::cout<<"result["<<kro.size()-i+ite<<"]= "<<result[kro.size()-i+ite]<<std::endl;
                //std::cout<<"result["<<kro.size()-i+ite+1<<"]= "<<result[kro.size()-i+ite+1]<<std::endl;
                  
                    
            }
            for(auto x:str)
            	kro[x].second++;
            
            nw=tmp;
        }
        sum-=kro[i].first;//*kro[i].second;

    }
    sum=0;
    for (auto x : li)
        sum += x;
    nw=0;
    for (std::size_t i = 0; i < li.size(); i++) {
        
        long long tmp = nwd(nw, li[i]);
        
//        if(tmp!=nw){
//            long long max=-MAXEL;
//            for(std::size_t j=i;j<li.size();j++){
//                max=std::max(max,nwd(li[j],nw))-li[j];
//            }
//            result[li.size()-i]=std::max(result[li.size()-i],sum+max);
//        }else{
            result[li.size()-i]=std::max(result[li.size()-i],sum-li[i]+nw);
//        }
        
        sum-=li[i];
        nw=tmp;
        
    }

   
    for (int i=1;i<=n;i++) {
        std::cout << result[i] << "\n";
    }

    
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 2ms
memory: 3360kb

input:

7
18 30 10 23 1 3 13

output:

1
31
54
72
85
95
98

result:

ok 7 lines

Test #2:

score: -5
Wrong Answer
time: 2ms
memory: 3276kb

input:

7
11 12 12 15 30 6 10

output:

1
31
46
58
72
86
96

result:

wrong answer 6th lines differ - expected: '84', found: '86'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #31:

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

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:

1
497
990
1476
1960
2428
2895
3359
3819
4274
4720
5164
5591
6009
6420
6829
7234
7633
8028
8422
8801
9177
9547
9915
10277
10636
10990
11335
11675
12006
12337
12667
12993
13312
13623
13934
14244
14543
14839
15135
15427
15716
16003
16286
16564
16838
17108
17378
17646
17914
18181
18444
18699
18941
19166...

result:

wrong answer 99th lines differ - expected: '24536', found: '24537'

Subtask #4:

score: 0
Wrong Answer

Test #51:

score: 8
Accepted
time: 2ms
memory: 3376kb

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:

1
1996
3990
5983
7975
9966
11955
13943
15928
17912
19895
21873
23849
25824
27796
29767
31737
33706
35674
37641
39607
41570
43531
45490
47447
49402
51354
53304
55251
57197
59142
61084
63024
64963
66900
68836
70770
72703
74632
76560
78487
80413
82337
84260
86182
88103
90023
91941
93856
95770
97683
995...

result:

ok 1270 lines

Test #52:

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

input:

1265
1 2 5 6 7 8 9 10 12 14 15 16 17 18 19 20 24 26 28 29 30 31 32 33 34 35 37 38 39 40 41 43 44 45 46 47 50 56 57 59 62 63 64 65 66 67 68 69 70 71 74 75 77 83 84 85 86 87 88 89 91 92 95 97 98 100 101 102 105 106 107 108 109 110 112 114 115 116 117 118 119 120 122 123 124 125 126 128 129 133 134 136...

output:

1
2001
4000
5998
7994
9989
11983
13976
15968
17957
19945
21932
23917
25901
27883
29864
31841
33817
35792
37766
39738
41709
43678
45646
47612
49575
51537
53496
55454
57411
59367
61321
63274
65225
67175
69124
71072
73019
74965
76909
78852
80794
82735
84675
86613
88549
90481
92412
94342
96271
98198
100...

result:

ok 1265 lines

Test #53:

score: 0
Accepted
time: 1ms
memory: 3448kb

input:

1291
1 2 4 5 8 9 11 12 14 18 19 21 22 23 24 25 28 30 31 32 33 34 35 36 37 39 41 42 43 44 45 48 52 53 54 57 58 61 62 63 64 65 67 71 72 73 74 76 77 78 80 81 82 85 88 89 91 92 97 99 100 101 102 103 104 105 106 107 108 110 113 114 115 118 120 121 122 123 124 126 128 129 132 134 135 137 140 141 142 143 1...

output:

1
2001
4000
5996
7990
9983
11975
13966
15956
17945
19933
21918
23902
25880
27857
29833
31808
33777
35745
37712
39677
41641
43604
45566
47527
49487
51446
53404
55361
57317
59268
61218
63166
65113
67059
69004
70945
72884
74822
76759
78695
80630
82563
84492
86419
88345
90270
92194
94117
96038
97958
998...

result:

ok 1291 lines

Test #54:

score: -8
Wrong Answer
time: 2ms
memory: 3328kb

input:

21
1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 19...

output:

1
2001
4000
5998
7995
9991
11986
13980
15973
17965
19956
21946
23935
25923
27910
29896
31881
33865
35848
39809
41790

result:

wrong answer 20th lines differ - expected: '37830', found: '39809'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%