Submission #932912

# Submission time Handle Problem Language Result Execution time Memory
932912 2024-02-24T13:52:41 Z parlimoos JOIRIS (JOI16_joiris) C++14
0 / 100
1 ms 352 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(){
    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 md = 0 ; md < k ; md++){
        sec = a , nm.cl();
        for(int i = 0 ; i < n - k + 1 ; i++){
            if(sec[i] % k == md) continue;
            int d = Minus(md , sec[i]);
            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()));
        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});
        }
        getOut();
    }
    cout << -1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -