Submission #226518

# Submission time Handle Problem Language Result Execution time Memory
226518 2020-04-24T06:58:12 Z Ruxandra985 Rope (JOI17_rope) C++14
55 / 100
2500 ms 12684 KB
#include <bits/stdc++.h>

using namespace std;
int v[1000010] , f[1000010] , sol[1000010] , w[1000010];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , m , i , j , curr , fmax , maxi , first;
    fscanf (fin,"%d%d",&n,&m);
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&v[i]);
    }

    for (i = 1 ; i <= m ; i++)
        sol[i] = 2000000000 * (m != 1);

    for (i = 1 ; i <= m ; i++){

        //if (i == 9)
          //  printf ("a");

        curr = 0;
        maxi = 0;
        fmax = 0;
        first = 0;

        memset (f , 0 , sizeof(f));

        /// cazul 1 : mereu 2k = 2k - 1

        for (j = 2 ; j <= n ; j += 2){

            /// v[j] = v[j - 1]

            if (v[j] == i || v[j - 1] == i){ /// astea 2 devin cu i
                curr = curr + (v[j] != i) + (v[j - 1] != i);
                first += 2;
            }
            else {
                f[v[j]]++;
                f[v[j - 1]]++;

                if (f[v[j]] > maxi){
                    maxi = f[v[j]];
                    fmax = v[j];
                }

                if (f[v[j - 1]] > maxi){
                    maxi = f[v[j - 1]];
                    fmax = v[j - 1];
                }

            }

        }
        if (n % 2){ /// ai sarit peste
            if (v[n] == i)
                first++;
            else {
                f[v[n]]++;
                if (f[v[n]] > maxi){
                    maxi = f[v[n]];
                    fmax = v[n];
                }

            }
        }

        curr = curr + n - first - f[fmax];

        sol[i] = min(sol[i] , curr);
        sol[fmax] = min(sol[fmax] , curr);

        /// --------------------------------------------------------------------------

        curr = 0;
        maxi = 0;
        fmax = 0;
        first = 0;

        memset (f , 0 , sizeof(f));

        /// cazul 1 : mereu 2k + 1 = 2k

        for (j = 2 ; j < n ; j += 2){

            /// v[j] = v[j - 1]

            if (v[j] == i || v[j + 1] == i){ /// astea 2 devin cu i
                curr = curr + (v[j] != i) + (v[j + 1] != i);
                first += 2;
            }
            else {
                f[v[j]]++;
                f[v[j + 1]]++;

                if (f[v[j]] > maxi){
                    maxi = f[v[j]];
                    fmax = v[j];
                }

                if (f[v[j + 1]] > maxi){
                    maxi = f[v[j + 1]];
                    fmax = v[j + 1];
                }

            }

        }

        if (v[1] == i)
            first++;
        else {
            f[v[1]]++;
            if (f[v[1]] > maxi){
                maxi = f[v[1]];
                fmax = v[1];
            }

        }


        if (n % 2 == 0){ /// ai sarit peste
            if (v[n] == i)
                first++;
            else {
                f[v[n]]++;
                if (f[v[n]] > maxi){
                    maxi = f[v[n]];
                    fmax = v[n];
                }

            }
        }

        curr = curr + n - first - f[fmax];

        sol[i] = min(sol[i] , curr);
        sol[fmax] = min(sol[fmax] , curr);




    }

    for (i = 1 ; i <= m ; i++)
        fprintf (fout,"%d\n",sol[i]);

    return 0;
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:10:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
rope.cpp:12:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4224 KB Output is correct
2 Correct 9 ms 4224 KB Output is correct
3 Correct 9 ms 4224 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 7 ms 4224 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 8 ms 4224 KB Output is correct
14 Correct 8 ms 4224 KB Output is correct
15 Correct 7 ms 4224 KB Output is correct
16 Correct 7 ms 4224 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 8 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 8 ms 4224 KB Output is correct
21 Correct 7 ms 4224 KB Output is correct
22 Correct 7 ms 4224 KB Output is correct
23 Correct 7 ms 4224 KB Output is correct
24 Correct 7 ms 4224 KB Output is correct
25 Correct 7 ms 4224 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4224 KB Output is correct
2 Correct 9 ms 4224 KB Output is correct
3 Correct 9 ms 4224 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 7 ms 4224 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 8 ms 4224 KB Output is correct
14 Correct 8 ms 4224 KB Output is correct
15 Correct 7 ms 4224 KB Output is correct
16 Correct 7 ms 4224 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 8 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 8 ms 4224 KB Output is correct
21 Correct 7 ms 4224 KB Output is correct
22 Correct 7 ms 4224 KB Output is correct
23 Correct 7 ms 4224 KB Output is correct
24 Correct 7 ms 4224 KB Output is correct
25 Correct 7 ms 4224 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
27 Correct 26 ms 4864 KB Output is correct
28 Correct 24 ms 4864 KB Output is correct
29 Correct 26 ms 4864 KB Output is correct
30 Correct 24 ms 4864 KB Output is correct
31 Correct 26 ms 4864 KB Output is correct
32 Correct 22 ms 4864 KB Output is correct
33 Correct 26 ms 4864 KB Output is correct
34 Correct 22 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4224 KB Output is correct
2 Correct 9 ms 4224 KB Output is correct
3 Correct 9 ms 4224 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 7 ms 4224 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 8 ms 4224 KB Output is correct
14 Correct 8 ms 4224 KB Output is correct
15 Correct 7 ms 4224 KB Output is correct
16 Correct 7 ms 4224 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 8 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 8 ms 4224 KB Output is correct
21 Correct 7 ms 4224 KB Output is correct
22 Correct 7 ms 4224 KB Output is correct
23 Correct 7 ms 4224 KB Output is correct
24 Correct 7 ms 4224 KB Output is correct
25 Correct 7 ms 4224 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
27 Correct 26 ms 4864 KB Output is correct
28 Correct 24 ms 4864 KB Output is correct
29 Correct 26 ms 4864 KB Output is correct
30 Correct 24 ms 4864 KB Output is correct
31 Correct 26 ms 4864 KB Output is correct
32 Correct 22 ms 4864 KB Output is correct
33 Correct 26 ms 4864 KB Output is correct
34 Correct 22 ms 4864 KB Output is correct
35 Correct 315 ms 5172 KB Output is correct
36 Correct 314 ms 5108 KB Output is correct
37 Correct 304 ms 5112 KB Output is correct
38 Correct 305 ms 5072 KB Output is correct
39 Correct 310 ms 5112 KB Output is correct
40 Correct 317 ms 5112 KB Output is correct
41 Correct 310 ms 5120 KB Output is correct
42 Correct 257 ms 5068 KB Output is correct
43 Correct 192 ms 4992 KB Output is correct
44 Correct 311 ms 4992 KB Output is correct
45 Correct 317 ms 5112 KB Output is correct
46 Correct 248 ms 4992 KB Output is correct
47 Correct 206 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4224 KB Output is correct
2 Correct 9 ms 4224 KB Output is correct
3 Correct 9 ms 4224 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 7 ms 4224 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 8 ms 4224 KB Output is correct
14 Correct 8 ms 4224 KB Output is correct
15 Correct 7 ms 4224 KB Output is correct
16 Correct 7 ms 4224 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 8 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 8 ms 4224 KB Output is correct
21 Correct 7 ms 4224 KB Output is correct
22 Correct 7 ms 4224 KB Output is correct
23 Correct 7 ms 4224 KB Output is correct
24 Correct 7 ms 4224 KB Output is correct
25 Correct 7 ms 4224 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
27 Correct 26 ms 4864 KB Output is correct
28 Correct 24 ms 4864 KB Output is correct
29 Correct 26 ms 4864 KB Output is correct
30 Correct 24 ms 4864 KB Output is correct
31 Correct 26 ms 4864 KB Output is correct
32 Correct 22 ms 4864 KB Output is correct
33 Correct 26 ms 4864 KB Output is correct
34 Correct 22 ms 4864 KB Output is correct
35 Correct 315 ms 5172 KB Output is correct
36 Correct 314 ms 5108 KB Output is correct
37 Correct 304 ms 5112 KB Output is correct
38 Correct 305 ms 5072 KB Output is correct
39 Correct 310 ms 5112 KB Output is correct
40 Correct 317 ms 5112 KB Output is correct
41 Correct 310 ms 5120 KB Output is correct
42 Correct 257 ms 5068 KB Output is correct
43 Correct 192 ms 4992 KB Output is correct
44 Correct 311 ms 4992 KB Output is correct
45 Correct 317 ms 5112 KB Output is correct
46 Correct 248 ms 4992 KB Output is correct
47 Correct 206 ms 5112 KB Output is correct
48 Execution timed out 2590 ms 12684 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4224 KB Output is correct
2 Correct 9 ms 4224 KB Output is correct
3 Correct 9 ms 4224 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 7 ms 4224 KB Output is correct
6 Correct 8 ms 4224 KB Output is correct
7 Correct 8 ms 4224 KB Output is correct
8 Correct 8 ms 4224 KB Output is correct
9 Correct 8 ms 4224 KB Output is correct
10 Correct 8 ms 4224 KB Output is correct
11 Correct 9 ms 4224 KB Output is correct
12 Correct 9 ms 4224 KB Output is correct
13 Correct 8 ms 4224 KB Output is correct
14 Correct 8 ms 4224 KB Output is correct
15 Correct 7 ms 4224 KB Output is correct
16 Correct 7 ms 4224 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 8 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 8 ms 4224 KB Output is correct
21 Correct 7 ms 4224 KB Output is correct
22 Correct 7 ms 4224 KB Output is correct
23 Correct 7 ms 4224 KB Output is correct
24 Correct 7 ms 4224 KB Output is correct
25 Correct 7 ms 4224 KB Output is correct
26 Correct 6 ms 4224 KB Output is correct
27 Correct 26 ms 4864 KB Output is correct
28 Correct 24 ms 4864 KB Output is correct
29 Correct 26 ms 4864 KB Output is correct
30 Correct 24 ms 4864 KB Output is correct
31 Correct 26 ms 4864 KB Output is correct
32 Correct 22 ms 4864 KB Output is correct
33 Correct 26 ms 4864 KB Output is correct
34 Correct 22 ms 4864 KB Output is correct
35 Correct 315 ms 5172 KB Output is correct
36 Correct 314 ms 5108 KB Output is correct
37 Correct 304 ms 5112 KB Output is correct
38 Correct 305 ms 5072 KB Output is correct
39 Correct 310 ms 5112 KB Output is correct
40 Correct 317 ms 5112 KB Output is correct
41 Correct 310 ms 5120 KB Output is correct
42 Correct 257 ms 5068 KB Output is correct
43 Correct 192 ms 4992 KB Output is correct
44 Correct 311 ms 4992 KB Output is correct
45 Correct 317 ms 5112 KB Output is correct
46 Correct 248 ms 4992 KB Output is correct
47 Correct 206 ms 5112 KB Output is correct
48 Execution timed out 2590 ms 12684 KB Time limit exceeded
49 Halted 0 ms 0 KB -