Submission #57148

# Submission time Handle Problem Language Result Execution time Memory
57148 2018-07-14T07:11:06 Z gs13105 JOIRIS (JOI16_joiris) C++17
100 / 100
4 ms 1068 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

int arr[60];
int cur[60];
int tmp[60];
int cnt[60];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, l, i, j, k;
    scanf("%d%d", &n, &l);
    for(i = 1; i <= n; i++)
        scanf("%d", &arr[i]);

    for(i = 0; i < l; i++)
    {
        for(j = 1; j <= n; j++)
        {
            cur[j] = arr[j];
            tmp[j] = (arr[j] + i) % l;
        }

        for(j = 1; j <= n - l + 1; j++)
        {
            cnt[j] = (l - tmp[j]) % l;
            for(k = j; k < j + l; k++)
                tmp[k] = (tmp[k] + cnt[j]) % l;
        }

        bool ok = 1;
        for(j = 1; j <= n; j++)
        {
            if(tmp[j])
            {
                ok = 0;
                break;
            }
        }
        if(!ok)
            continue;

        vector<pair<int, int>> res;
        for(j = 1; j <= n - l + 1; j++)
        {
            for(k = 0; k < cnt[j]; k++)
                res.push_back({ 2, j });

            int mx = 0;
            for(k = j; k < j + l; k++)
                mx = max(mx, cur[k]);

            int mn = 1e9;
            for(k = 1; k <= n; k++)
            {
                if(j <= k && k < j + l)
                    cur[k] += cnt[j];
                else
                {
                    while(cur[k] < mx + cnt[j])
                    {
                        res.push_back({ 1, k });
                        cur[k] += l;
                    }
                }

                mn = min(mn, cur[k]);
            }

            for(k = 1; k <= n; k++)
                cur[k] -= mn;
        }

        int mx = 0;
        for(j = 1; j <= n; j++)
            mx = max(mx, cur[j]);

        for(j = 1; j <= n; j++)
        {
            while(cur[j] < mx)
            {
                res.push_back({ 1, j });
                cur[j] += l;
            }
        }

        printf("%d\n", (int)res.size());
        for(auto &p : res)
            printf("%d %d\n", p.first, p.second);
        return 0;
    }

    printf("-1\n");
    return 0;
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &l);
     ~~~~~^~~~~~~~~~~~~~~~
joiris.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 680 KB Output is correct
5 Correct 3 ms 700 KB Output is correct
6 Correct 3 ms 720 KB Output is correct
7 Correct 3 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 748 KB Output is correct
11 Correct 3 ms 756 KB Output is correct
12 Correct 2 ms 756 KB Output is correct
13 Correct 2 ms 756 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 664 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 4 ms 788 KB Output is correct
20 Correct 2 ms 788 KB Output is correct
21 Correct 3 ms 788 KB Output is correct
22 Correct 3 ms 816 KB Output is correct
23 Correct 3 ms 820 KB Output is correct
24 Correct 2 ms 944 KB Output is correct
25 Correct 3 ms 944 KB Output is correct
26 Correct 2 ms 944 KB Output is correct
27 Correct 3 ms 944 KB Output is correct
28 Correct 3 ms 944 KB Output is correct
29 Correct 3 ms 944 KB Output is correct
30 Correct 2 ms 944 KB Output is correct
31 Correct 2 ms 944 KB Output is correct
32 Correct 2 ms 944 KB Output is correct
33 Correct 2 ms 944 KB Output is correct
34 Correct 2 ms 944 KB Output is correct
35 Correct 3 ms 944 KB Output is correct
36 Correct 3 ms 944 KB Output is correct
37 Correct 3 ms 944 KB Output is correct
38 Correct 2 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 3 ms 664 KB Output is correct
17 Correct 3 ms 672 KB Output is correct
18 Correct 3 ms 672 KB Output is correct
19 Correct 2 ms 672 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
21 Correct 3 ms 700 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 3 ms 720 KB Output is correct
24 Correct 2 ms 720 KB Output is correct
25 Correct 3 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 756 KB Output is correct
28 Correct 2 ms 756 KB Output is correct
29 Correct 2 ms 756 KB Output is correct
30 Correct 3 ms 760 KB Output is correct
31 Correct 3 ms 760 KB Output is correct
32 Correct 3 ms 764 KB Output is correct
33 Correct 3 ms 764 KB Output is correct
34 Correct 2 ms 764 KB Output is correct
35 Correct 4 ms 788 KB Output is correct
36 Correct 2 ms 788 KB Output is correct
37 Correct 3 ms 788 KB Output is correct
38 Correct 3 ms 816 KB Output is correct
39 Correct 3 ms 820 KB Output is correct
40 Correct 2 ms 944 KB Output is correct
41 Correct 3 ms 944 KB Output is correct
42 Correct 2 ms 944 KB Output is correct
43 Correct 3 ms 944 KB Output is correct
44 Correct 3 ms 944 KB Output is correct
45 Correct 3 ms 944 KB Output is correct
46 Correct 2 ms 944 KB Output is correct
47 Correct 2 ms 944 KB Output is correct
48 Correct 2 ms 944 KB Output is correct
49 Correct 2 ms 944 KB Output is correct
50 Correct 2 ms 944 KB Output is correct
51 Correct 3 ms 944 KB Output is correct
52 Correct 3 ms 944 KB Output is correct
53 Correct 3 ms 944 KB Output is correct
54 Correct 2 ms 944 KB Output is correct
55 Correct 2 ms 944 KB Output is correct
56 Correct 3 ms 944 KB Output is correct
57 Correct 2 ms 944 KB Output is correct
58 Correct 2 ms 944 KB Output is correct
59 Correct 2 ms 944 KB Output is correct
60 Correct 3 ms 944 KB Output is correct
61 Correct 2 ms 944 KB Output is correct
62 Correct 2 ms 944 KB Output is correct
63 Correct 2 ms 944 KB Output is correct
64 Correct 2 ms 944 KB Output is correct
65 Correct 3 ms 944 KB Output is correct
66 Correct 2 ms 944 KB Output is correct
67 Correct 2 ms 944 KB Output is correct
68 Correct 3 ms 944 KB Output is correct
69 Correct 4 ms 944 KB Output is correct
70 Correct 4 ms 944 KB Output is correct
71 Correct 3 ms 948 KB Output is correct
72 Correct 4 ms 952 KB Output is correct
73 Correct 3 ms 956 KB Output is correct
74 Correct 3 ms 960 KB Output is correct
75 Correct 3 ms 1068 KB Output is correct
76 Correct 3 ms 1068 KB Output is correct
77 Correct 2 ms 1068 KB Output is correct
78 Correct 2 ms 1068 KB Output is correct
79 Correct 3 ms 1068 KB Output is correct
80 Correct 2 ms 1068 KB Output is correct
81 Correct 2 ms 1068 KB Output is correct
82 Correct 3 ms 1068 KB Output is correct
83 Correct 2 ms 1068 KB Output is correct
84 Correct 0 ms 1068 KB Output is correct
85 Correct 3 ms 1068 KB Output is correct
86 Correct 3 ms 1068 KB Output is correct
87 Correct 3 ms 1068 KB Output is correct
88 Correct 3 ms 1068 KB Output is correct
89 Correct 2 ms 1068 KB Output is correct
90 Correct 2 ms 1068 KB Output is correct
91 Correct 3 ms 1068 KB Output is correct
92 Correct 2 ms 1068 KB Output is correct