답안 #932941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932941 2024-02-24T15:27:52 Z parlimoos JOIRIS (JOI16_joiris) C++14
0 / 100
0 ms 600 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

int n , k;
vector<int> a , sec , nm;
vector<arr(2)> o;

void getOut(){
    cout << (int)o.size() << endl;
    for(auto el : o) cout << el[0] << " " << el[1] << endl;
    exit(0);
}
int Minus(int a , int b){
    int res = a - b;
    if(res < 0) return res + k;
    return res;
}
void addRng(int l , int r , int val){
    for(int i = l ; i <= r ; i++) sec[i] += val;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;
    for(int i = 0 ; i < n ; i++){
        int d;
        cin >> d;
        a.pb(d);
    }
    while(true){
        if(*(max_element(a.bg() , a.end())) < k) break;
        for(int i = 0 ; i < n ; i++){
            if(a[i] < k) o.pb({1 , i + 1}) , a[i] += k;
            a[i] -= k;
        }
    }
    // for(int el : a) cout << el << " ";
    // cout << endl;
    if(*(max_element(a.bg() , a.end())) == 0) getOut();
    for(int md = 0 ; md < k ; md++){
        sec = a , nm.cl();
        for(int i = 0 ; i < n - k + 1 ; i++){
            if(sec[i] % k == md){
                nm.pb(0);
                continue;
            }
            int d = Minus(md , sec[i] % k);
            addRng(i , i + k - 1 , d);
            nm.pb(d);
        }
        bool flg = 1;
        for(int i = n - k + 1 ; i < n ; i++) if(sec[i] % k != md) flg = 0;
        if(!flg) continue;
        for(int i = 0 ; i < n - k + 1 ; i++){
            if(nm[i] == 0) continue;
            // if(i == 1) cout << a[0] << "|\n";
            for(int j = 0 ; j < nm[i] ; j++) o.pb({2 , i + 1});
            for(int j = 0 ; j < n ; j++){
                if(j >= i and j < i + k) continue;
                if(a[j] + k < a[i] + nm[i]){
                    a[j] += k + k - nm[i];
                    o.pb({1 , j + 1}) , o.pb({1 , j + 1});
                }else if(a[j] < a[i] + nm[i]){
                    // if(i == 1 and j == 0) cout << a[j] << "|\n";
                    a[j] += k - nm[i];
                    o.pb({1 , j + 1});
                }else a[j] -= nm[i];
                // if(i == 1 and j == 0) cout << a[j] << "!\n";
            }
            // if(i == 0) cout << a[i] << "*\n";
            if(*(max_element(a.bg() , a.end())) < k) continue;
            for(int j = 0 ; j < n ; j++){
                if(a[j] < k) o.pb({1 , j + 1}) , a[j] += k;
                a[j] -= k;
            }
        }
        int mx = *(max_element(a.bg() , a.end()));
        if(mx == *(min_element(a.bg() , a.end()))) getOut();
        for(int i = 0 ; i < n ; i++){
            int d = (mx - a[i]) / k;
            for(int j = 0 ; j < d ; j++) o.pb({1 , i + 1});
            a[i] += d * k;
        }
        // for(int el : a) cout << el << " ";
        // cout << endl;
        getOut();
    }
    cout << "-1\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Incorrect 0 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Incorrect 0 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Incorrect 0 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -