답안 #932975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932975 2024-02-24T16:36:22 Z parlimoos JOIRIS (JOI16_joiris) C++14
0 / 100
1 ms 348 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);
    }
    int mx = *(max_element(a.bg() , a.end()));
    for(int i = 0 ; i < n ; i++){
        int d = (mx - a[i] + k - 1) / k;
        for(int j = 0 ; j < d ; j++) o.pb({1 , i + 1});
        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;
            int mxx = *(max_element(&a[i] , &a[i + k]));
            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 < mxx + nm[i]){
                    a[j] += k + k - nm[i];
                    o.pb({1 , j + 1}) , o.pb({1 , j + 1});
                }else if(a[j] < mxx + 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";
            int mx = *(max_element(a.bg() , a.end()));
            for(int i = 0 ; i < n ; i++){
                int d = (mx - a[i] + k - 1) / k;
                for(int j = 0 ; j < d ; j++) o.pb({1 , i + 1});
                a[i] %= k;
            }
        }
        // for(int el : a) cout << el << " ";
        // cout << endl;
        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();
    }
    // if(n == 2 and a[0] == 0 and a[1] == 1) while(true);
    cout << "-1\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -