Submission #429554

# Submission time Handle Problem Language Result Execution time Memory
429554 2021-06-16T06:32:48 Z 반딧불(#7598) GCD-sum (CPSPC17_gcds) C++17
10 / 100
2000 ms 4540 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
ll arr[500002];
ll DP[32768][15];
ll GCD[32768];

int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%lld", &arr[i]);
    for(int i=1; i<(1<<n); i++){
        for(int j=0; j<n; j++){
            if((i>>j)&1){
                if(!GCD[i]) GCD[i] = arr[j];
                else GCD[i] = __gcd(GCD[i], arr[j]);
            }
        }
    }

    for(int i=1; i<n; i++) DP[0][i] = -1e18;

    for(int i=1; i<(1<<n); i++){
        DP[i][0] = -1e18;
        for(int j=i; j; j=(j-1)&i){
            for(int k=n; k>=1; k--){
                DP[i][k] = max(DP[i][k], DP[i^j][k-1] + GCD[j]);
            }
        }
    }

    for(int i=1; i<=n; i++) printf("%lld\n", DP[(1<<n)-1][i]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for(int i=0; i<n; i++) scanf("%lld", &arr[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 317 ms 4292 KB Output is correct
17 Correct 319 ms 4372 KB Output is correct
18 Correct 321 ms 4540 KB Output is correct
19 Correct 320 ms 4332 KB Output is correct
20 Correct 326 ms 4348 KB Output is correct
21 Correct 321 ms 4384 KB Output is correct
22 Correct 366 ms 4380 KB Output is correct
23 Correct 341 ms 4388 KB Output is correct
24 Correct 340 ms 4436 KB Output is correct
25 Correct 317 ms 4368 KB Output is correct
26 Correct 321 ms 4432 KB Output is correct
27 Correct 324 ms 4384 KB Output is correct
28 Correct 363 ms 4328 KB Output is correct
29 Correct 332 ms 4300 KB Output is correct
30 Correct 323 ms 4504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 3492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 317 ms 4292 KB Output is correct
17 Correct 319 ms 4372 KB Output is correct
18 Correct 321 ms 4540 KB Output is correct
19 Correct 320 ms 4332 KB Output is correct
20 Correct 326 ms 4348 KB Output is correct
21 Correct 321 ms 4384 KB Output is correct
22 Correct 366 ms 4380 KB Output is correct
23 Correct 341 ms 4388 KB Output is correct
24 Correct 340 ms 4436 KB Output is correct
25 Correct 317 ms 4368 KB Output is correct
26 Correct 321 ms 4432 KB Output is correct
27 Correct 324 ms 4384 KB Output is correct
28 Correct 363 ms 4328 KB Output is correct
29 Correct 332 ms 4300 KB Output is correct
30 Correct 323 ms 4504 KB Output is correct
31 Incorrect 1 ms 204 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 3492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 317 ms 4292 KB Output is correct
17 Correct 319 ms 4372 KB Output is correct
18 Correct 321 ms 4540 KB Output is correct
19 Correct 320 ms 4332 KB Output is correct
20 Correct 326 ms 4348 KB Output is correct
21 Correct 321 ms 4384 KB Output is correct
22 Correct 366 ms 4380 KB Output is correct
23 Correct 341 ms 4388 KB Output is correct
24 Correct 340 ms 4436 KB Output is correct
25 Correct 317 ms 4368 KB Output is correct
26 Correct 321 ms 4432 KB Output is correct
27 Correct 324 ms 4384 KB Output is correct
28 Correct 363 ms 4328 KB Output is correct
29 Correct 332 ms 4300 KB Output is correct
30 Correct 323 ms 4504 KB Output is correct
31 Incorrect 1 ms 204 KB Output isn't correct
32 Halted 0 ms 0 KB -