제출 #57148

#제출 시각아이디문제언어결과실행 시간메모리
57148gs13105JOIRIS (JOI16_joiris)C++17
100 / 100
4 ms1068 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...