Submission #341083

# Submission time Handle Problem Language Result Execution time Memory
341083 2020-12-29T01:23:54 Z rrrr10000 JOIRIS (JOI16_joiris) C++14
0 / 100
1 ms 748 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define dame(a) {out(a);return 0;}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
vp ans;
void tate(int i){
    ans.pb(1,i+1);
}
void yoko(int i){
    ans.pb(2,i+1);
}
int main(){
    ll n,k;cin>>n>>k;
    assert(k==2&&n%2==0);
    vi v(n);rep(i,n)cin>>v[i];
    ll ma=0;
    rep(i,n)chmax(ma,v[i]);
    rep(i,n)while(v[i]<ma){
        tate(i);
        v[i]+=k;
    }
    rep(i,n)v[i]-=ma;
    auto check=[&](){
        bool done=true;
        rep(i,n)if(v[i])done=false;
        if(done){
            out(ans.size());for(auto x:ans)cout<<x.fi<<' '<<x.se<<endl;
        }
        return done;
    };
    if(check())return 0;
    while(true){
        bool found=false;
        for(int i=n-1;i>0;i--)if(v[i]==0&&v[i-1]==1){
            yoko(i-1);
            rep(j,n)if(j!=i-1)tate(j);
            v[i]=1;v[i-1]=0;
            found=true;
            break;
        }
        if(!found)break;
    }
    ll cnt=0;
    rep(i,n)if(v[i])cnt++;
    assert(cnt!=0&&cnt!=n);
    rep(i,n-1)assert(v[i]==0||v[i+1]==1);
    if(cnt%2==1&&n%2==0)dame(-1);
    if(cnt%2==0&&n%2==1){
        rep(i,n){
            if(v[i]==0)tate(i);
            v[i]=1-v[i];
        }
    }
    rep(i,n-1)if(v[i]==0){
        assert(v[i+1]==0);
        yoko(i);
        v[i]=1;v[i+1]=1;
    }
    assert(v[n-1]==1);
    assert(ans.size()<=1000);
    out(ans.size());
    for(auto x:ans)cout<<x.fi<<' '<<x.se<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Runtime error 1 ms 748 KB Execution killed with signal 6 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Runtime error 1 ms 748 KB Execution killed with signal 6 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Runtime error 1 ms 748 KB Execution killed with signal 6 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -