답안 #341101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341101 2020-12-29T02:16:47 Z rrrr10000 JOIRIS (JOI16_joiris) C++14
컴파일 오류
0 ms 0 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;
    vi dif(n-1);
    rep(i,n-1)dif[i]=v[i+1]-v[i];
    vi sum(k);
    rep(i,n-1)sum[i%k]+=dif[i];
    rep(i,k)if(sum[i]%k!=0)dame(-1);
    assert(k==2);
    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;
    ll cnt=0;
    rep(i,n)if(v[i])cnt++;
    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];
        }
    }
    ll c=0;
    for(int i=n-1;i>=0;i--){
        if(v[i]==0)c++;
        else{
            if(c%2){
                yoko(i);
                rep(j,n)if(j!=i&&j!=i+1)tate(j);
                tate(i+1);
                v[i]=0;v[i+1]=1;
                c=1;
            }
            else c=0;
        }
    }
    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()<=10000);
    out(ans.size());
    for(auto x:ans)cout<<x.fi<<' '<<x.se<<endl;
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:41:22: error: 'v' was not declared in this scope
   41 |     rep(i,n-1)dif[i]=v[i+1]-v[i];
      |                      ^