Submission #1036562


Source Code Expand

#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
void ng(){
  puts("-1");
  exit(0);
}
typedef vector<int> vi;
typedef vector<pi> vp;

const int M=5e8;

void rot(vp& res){
  for(auto& p:res){
    pi nxt=mp(-p.sc,p.fr);
    p=nxt;
  }
}

vp solve(vi ar){
  int n=ar.size();
  if(n==4){
    vp res={{0,0},{1,0},{1,1},{0,1}};
    return res;
  }

  bool suc=false;
  vi pvar=ar;
  vector<int> pv;
  REP(i,n) if(ar[i]==1 && ar[(i+1)%n]==1 && ar[(i+2)%n]==3){
    REP(j,i) pv.pb(ar[j+1]);

    rotate(ar.begin(),ar.begin()+i,ar.end());
    suc=true;
    break;
  }
  assert(suc);
  vi chil=ar;
  ar.erase(ar.begin()+1);
  ar.erase(ar.begin()+1);

  vp res=solve(ar);
  prl;
  debug(ALL(ar));
  debug(ALL(res));
  int y=res[0].sc,x=res[0].fr;

  for(auto& p:res){
    if(p.sc<y) --p.sc;
    if(p.fr>x) ++p.fr;
  }

  res[0].sc--;
  res.insert(res.begin()+1,res[0]);
  res[1].fr++;
  res.insert(res.begin()+2,res[1]);
  res[2].sc++;
    debug(ALL(res));

  if(!pv.empty()){
    rotate(res.begin(),res.begin()+res.size()-pv.size(),res.end());
    int sign=0;
    for(auto e:pv){
      if(e==3) --sign;
      else ++sign;
    }
    sign=(sign%4+4)%4;
    REP(_,sign) rot(res);
  }
  debug(ALL(pvar));
  debug(ALL(res));
  return res;
}
int main(){
  int n;
  cin>>n;
  int one=0,thr=0;
  vi ar(n);
  REP(i,n){
    cin>>ar[i];
    if(ar[i]==90) ++one;
    else ++thr;
    ar[i]/=90;
  }
  if(n&1) ng();
  if(one-thr!=4) ng();

  vp res=solve(ar);

  for(auto p:res){
    printf("%d %d\n",p.fr+M,p.sc+M);
  }






  return 0;
}



Submission Info

Submission Time
Task I - 90 and 270
User hogloid
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 2809 Byte
Status AC
Exec Time 13 ms
Memory 4608 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 3 ms 256 KB
001.txt AC 3 ms 256 KB
002.txt AC 3 ms 256 KB
003.txt AC 8 ms 2304 KB
004.txt AC 4 ms 640 KB
005.txt AC 4 ms 896 KB
006.txt AC 6 ms 1536 KB
007.txt AC 4 ms 640 KB
008.txt AC 3 ms 384 KB
009.txt AC 4 ms 768 KB
010.txt AC 8 ms 2432 KB
011.txt AC 3 ms 256 KB
012.txt AC 5 ms 1152 KB
013.txt AC 4 ms 1024 KB
014.txt AC 3 ms 384 KB
015.txt AC 3 ms 512 KB
016.txt AC 5 ms 1280 KB
017.txt AC 3 ms 256 KB
018.txt AC 5 ms 1152 KB
019.txt AC 3 ms 564 KB
020.txt AC 8 ms 2944 KB
021.txt AC 3 ms 256 KB
022.txt AC 7 ms 2688 KB
023.txt AC 13 ms 4608 KB
024.txt AC 12 ms 4608 KB
025.txt AC 12 ms 4352 KB
026.txt AC 11 ms 4096 KB
027.txt AC 11 ms 3968 KB
028.txt AC 10 ms 3712 KB
029.txt AC 11 ms 4096 KB
030.txt AC 10 ms 3712 KB
031.txt AC 10 ms 3712 KB
032.txt AC 10 ms 3584 KB
033.txt AC 9 ms 3456 KB
034.txt AC 9 ms 3456 KB
035.txt AC 9 ms 3456 KB
036.txt AC 9 ms 3328 KB
037.txt AC 9 ms 3328 KB
038.txt AC 9 ms 3328 KB
039.txt AC 9 ms 3328 KB
040.txt AC 8 ms 3328 KB
041.txt AC 8 ms 3328 KB
042.txt AC 7 ms 3328 KB
043.txt AC 3 ms 256 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 3 ms 256 KB