제출 #1220115

#제출 시각아이디문제언어결과실행 시간메모리
122011512345678JOIRIS (JOI16_joiris)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=51;

int n, k, a[nx], mx, h[nx], sm;
vector<pair<int, int>> res;

void add(int idx)
{
    int l=idx, r=idx+k-1;
    for (int i=1; i<=n; i++) if (i<l||r<i) res.push_back({1, i}), h[i]+=k-1;
    res.push_back({2, idx});
    for (int i=l;i <=r; i++) res.push_back({1, i}), h[i]+=k;
    int mx=0;
    for (int i=1; i<=n; i++) mx=max(mx, h[i]);
    for (int i=1; i<=n; i++) while (h[i]<mx) h[i]+=k, res.push_back({1, i});
    for (int i=1; i<=n; i++) h[i]=h[i]%k;
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>h[i], mx=max(mx, h[i]), sm+=h[i];
    for (int i=1; i<=n; i++) while (h[i]<mx) res.push_back({1, i}), h[i]+=k;
    for (int i=1; i<=n; i++) h[i]=h[i]%k;
    for (int i=2; i<=n-k+1; i++) 
    {
        while (h[i]!=h[i-1]) 
        {
            add(i);
            //cout<<"after add "<<i<<" : ";
            //for (int j=1; j<=n; j++) cout<<h[j]<<' ';
            //cout<<'\n';
        }
        for (int j=1; j<i; j++) if (h[j]!=h[i]) cout<<1/0;
    }
    if (2*k-1==n)
    {
        while (h[1]!=h[n]) add(1);
    }
    for (int i=1; i<=n; i++) if (h[i]!=h[1]) return cout<<-1, 0;
    cout<<res.size()<<'\n';
    for (auto [x, y]:res) cout<<x<<' '<<y<<'\n';
}

/*
6 1
0 0 0 2 2 0

8 2
0 1 0 1 0 1 0 1
*/

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

joiris.cpp: In function 'int main()':
joiris.cpp:38:56: warning: division by zero [-Wdiv-by-zero]
   38 |         for (int j=1; j<i; j++) if (h[j]!=h[i]) cout<<1/0;
      |                                                       ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...