답안 #205639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205639 2020-02-29T11:10:32 Z Kastanda Rope (JOI17_rope) C++11
45 / 100
2500 ms 2680 KB
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, A[N], dp[N][2][2];
inline void smin(int &a, int b) {a = min(a, b);}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
        scanf("%d", &A[i]);
    for (int c = 1; c <= m; c ++)
    {
        int Mn = 0;
        for (int i = 1; i <= n; i ++)
            if (A[i] != c) Mn ++;
        for (int d = 1; d <= m; d ++)
            if (d != c)
            {
                int cls[2] = {c, d}, cnt[2] = {0, 0};
                memset(dp, 63, sizeof(dp));
                for (int i = 1; i <= n; i ++)
                {
                    cnt[0] += (A[i] != cls[0]);
                    cnt[1] += (A[i] != cls[1]);
                    dp[i][0][0] = dp[i][0][1] = cnt[0];
                    dp[i][1][0] = dp[i][1][1] = cnt[1];
                }
                for (int i = 1; i < n; i ++)
                    for (int w = 0; w <= 1; w ++)
                        for (int p = 0; p <= 1; p ++)
                        {
                            smin(dp[i + 1][w][!p], dp[i][w][p] + (A[i + 1] != cls[w]));
                            if (!p) smin(dp[i + 1][!w][1], dp[i][w][p] + (A[i + 1] != cls[!w]));
                        }
                for (int w = 0; w <= 1; w ++)
                    for (int p = 0; p <= 1; p ++)
                        Mn = min(Mn, dp[n][w][p]);
            }
        printf("%d\n", Mn);
    }
    return 0;
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
rope.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1912 KB Output is correct
2 Correct 10 ms 1912 KB Output is correct
3 Correct 10 ms 1912 KB Output is correct
4 Correct 6 ms 1912 KB Output is correct
5 Correct 6 ms 1912 KB Output is correct
6 Correct 11 ms 1912 KB Output is correct
7 Correct 9 ms 1912 KB Output is correct
8 Correct 8 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 10 ms 1912 KB Output is correct
12 Correct 10 ms 1912 KB Output is correct
13 Correct 8 ms 1912 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1912 KB Output is correct
16 Correct 6 ms 1912 KB Output is correct
17 Correct 9 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 8 ms 1944 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 1912 KB Output is correct
24 Correct 6 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1912 KB Output is correct
2 Correct 10 ms 1912 KB Output is correct
3 Correct 10 ms 1912 KB Output is correct
4 Correct 6 ms 1912 KB Output is correct
5 Correct 6 ms 1912 KB Output is correct
6 Correct 11 ms 1912 KB Output is correct
7 Correct 9 ms 1912 KB Output is correct
8 Correct 8 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 10 ms 1912 KB Output is correct
12 Correct 10 ms 1912 KB Output is correct
13 Correct 8 ms 1912 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1912 KB Output is correct
16 Correct 6 ms 1912 KB Output is correct
17 Correct 9 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 8 ms 1944 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 1912 KB Output is correct
24 Correct 6 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 96 ms 2484 KB Output is correct
28 Correct 27 ms 2424 KB Output is correct
29 Correct 78 ms 2424 KB Output is correct
30 Correct 33 ms 2424 KB Output is correct
31 Correct 90 ms 2552 KB Output is correct
32 Correct 26 ms 2424 KB Output is correct
33 Correct 76 ms 2424 KB Output is correct
34 Correct 33 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1912 KB Output is correct
2 Correct 10 ms 1912 KB Output is correct
3 Correct 10 ms 1912 KB Output is correct
4 Correct 6 ms 1912 KB Output is correct
5 Correct 6 ms 1912 KB Output is correct
6 Correct 11 ms 1912 KB Output is correct
7 Correct 9 ms 1912 KB Output is correct
8 Correct 8 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 10 ms 1912 KB Output is correct
12 Correct 10 ms 1912 KB Output is correct
13 Correct 8 ms 1912 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1912 KB Output is correct
16 Correct 6 ms 1912 KB Output is correct
17 Correct 9 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 8 ms 1944 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 1912 KB Output is correct
24 Correct 6 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 96 ms 2484 KB Output is correct
28 Correct 27 ms 2424 KB Output is correct
29 Correct 78 ms 2424 KB Output is correct
30 Correct 33 ms 2424 KB Output is correct
31 Correct 90 ms 2552 KB Output is correct
32 Correct 26 ms 2424 KB Output is correct
33 Correct 76 ms 2424 KB Output is correct
34 Correct 33 ms 2552 KB Output is correct
35 Execution timed out 2595 ms 2680 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1912 KB Output is correct
2 Correct 10 ms 1912 KB Output is correct
3 Correct 10 ms 1912 KB Output is correct
4 Correct 6 ms 1912 KB Output is correct
5 Correct 6 ms 1912 KB Output is correct
6 Correct 11 ms 1912 KB Output is correct
7 Correct 9 ms 1912 KB Output is correct
8 Correct 8 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 10 ms 1912 KB Output is correct
12 Correct 10 ms 1912 KB Output is correct
13 Correct 8 ms 1912 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1912 KB Output is correct
16 Correct 6 ms 1912 KB Output is correct
17 Correct 9 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 8 ms 1944 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 1912 KB Output is correct
24 Correct 6 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 96 ms 2484 KB Output is correct
28 Correct 27 ms 2424 KB Output is correct
29 Correct 78 ms 2424 KB Output is correct
30 Correct 33 ms 2424 KB Output is correct
31 Correct 90 ms 2552 KB Output is correct
32 Correct 26 ms 2424 KB Output is correct
33 Correct 76 ms 2424 KB Output is correct
34 Correct 33 ms 2552 KB Output is correct
35 Execution timed out 2595 ms 2680 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1912 KB Output is correct
2 Correct 10 ms 1912 KB Output is correct
3 Correct 10 ms 1912 KB Output is correct
4 Correct 6 ms 1912 KB Output is correct
5 Correct 6 ms 1912 KB Output is correct
6 Correct 11 ms 1912 KB Output is correct
7 Correct 9 ms 1912 KB Output is correct
8 Correct 8 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 10 ms 1912 KB Output is correct
12 Correct 10 ms 1912 KB Output is correct
13 Correct 8 ms 1912 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1912 KB Output is correct
16 Correct 6 ms 1912 KB Output is correct
17 Correct 9 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 8 ms 1944 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 6 ms 1912 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 1912 KB Output is correct
24 Correct 6 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 96 ms 2484 KB Output is correct
28 Correct 27 ms 2424 KB Output is correct
29 Correct 78 ms 2424 KB Output is correct
30 Correct 33 ms 2424 KB Output is correct
31 Correct 90 ms 2552 KB Output is correct
32 Correct 26 ms 2424 KB Output is correct
33 Correct 76 ms 2424 KB Output is correct
34 Correct 33 ms 2552 KB Output is correct
35 Execution timed out 2595 ms 2680 KB Time limit exceeded
36 Halted 0 ms 0 KB -