QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618687#9439. Aim Highhos_lyricAC ✓1ms3884kbC++143.8kb2024-10-07 06:39:262024-10-07 06:39:26

Judging History

This is the latest submission verdict.

  • [2024-10-07 06:39:26]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3884kb
  • [2024-10-07 06:39:26]
  • Submitted

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


vector<vector<int>> ans;
map<pair<int, int>, int> f;

void oper(const vector<int> &op) {
  ans.push_back(op);
  assert(abs(op[0] - op[2]) + abs(op[1] - op[3]) == 1);
  assert(abs(op[4] - op[2]) + abs(op[5] - op[3]) == 1);
  assert((op[0] - op[2]) * (op[4] - op[2]) + (op[1] - op[3]) * (op[5] - op[3]) == 0);
  assert(f[make_pair(op[0], op[1])] > 0);
  assert(f[make_pair(op[2], op[3])] > 0);
  --f[make_pair(op[0], op[1])];
  --f[make_pair(op[2], op[3])];
  ++f[make_pair(op[4], op[5])];
}

/*
  +
  --
  
  r^-2 + r^-1 = r^0
  r = (1+sqrt(5))/2
  \sum[x] \sum[y<=0] r^(-|x|+y) = (11+5sqrt(5))/2 = r^5
  
  from below
  1111111111111111
  1221122112211221
  1222222112222221
  1222222222222221
  
  from above
  y= 4:    1
  y= 3:    11
  y= 2:   1111
  y= 1:  112211
  y= 0: 12322321
  
  y= 0: 12322321
        01211210
  y=-1: 13311331
        02200220
  y=-2: 22222222
*/

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    int N;
    scanf("%d", &N);
    
    if (N <= 4) {
      ans.clear();
      f.clear();
      for (int y = -5; y <= 0; ++y) for (int x = 0; x < 16; ++x) ++f[make_pair(x, y)];
      for (int y = -5; y <= -3; ++y) {
        const int w = 2 << (y - (-5));
        for (int x = 0; x < 16; x += w << 1) {
          for (int i = 0; i < w - 1; ++i) {
            oper({x+w-1-i - 1, y, x+w-1-i, y, x+w-1-i, y+1});
            oper({x+w  +i + 1, y, x+w  +i, y, x+w  +i, y+1});
          }
        }
      }
// for(auto&kv:f)if(kv.first.second==-2)cerr<<kv<<endl;
      for (const int x : {1, 5}) for (int i = 0; i < 2; ++i) {
        oper({x+0, -2, x+1, -2, x+1, -1});
        oper({x+3, -2, x+2, -2, x+2, -1});
      }
      for (const int i : {0, 1, 1, 2}) {
        oper({4-i - 1, -1, 4-i, -1, 4-i, 0});
        oper({5+i + 1, -1, 5+i, -1, 5+i, 0});
      }
      for (const int i : {0, 0, 1, 2}) {
        oper({4-i - 1, 0, 4-i, 0, 4-i, 1});
        oper({5+i + 1, 0, 5+i, 0, 5+i, 1});
      }
// for(auto&kv:f)if(kv.first.second==1)cerr<<kv<<endl;
      oper({2, 1, 3, 1, 3, 2});
      oper({5, 1, 4, 1, 4, 2});
      oper({4, 1, 5, 1, 5, 2});
      oper({7, 1, 6, 1, 6, 2});
      oper({3, 2, 4, 2, 4, 3});
      oper({6, 2, 5, 2, 5, 3});
      oper({5, 3, 4, 3, 4, 4});
      
      printf("%d\n", (int)ans.size());
      for (const auto &op : ans) {
        for (int i = 0; i < 6; ++i) {
          if (i) printf(" ");
          printf("%d", op[i]);
        }
        puts("");
      }
    } else {
      puts("-1");
    }
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

input:

1
1

output:

65
0 -5 1 -5 1 -4
3 -5 2 -5 2 -4
4 -5 5 -5 5 -4
7 -5 6 -5 6 -4
8 -5 9 -5 9 -4
11 -5 10 -5 10 -4
12 -5 13 -5 13 -4
15 -5 14 -5 14 -4
2 -4 3 -4 3 -3
5 -4 4 -4 4 -3
1 -4 2 -4 2 -3
6 -4 5 -4 5 -3
0 -4 1 -4 1 -3
7 -4 6 -4 6 -3
10 -4 11 -4 11 -3
13 -4 12 -4 12 -3
9 -4 10 -4 10 -3
14 -4 13 -4 13 -3
8 -4 9 ...

result:

ok Output is valid. OK

Test #2:

score: 0
Accepted
time: 1ms
memory: 3884kb

input:

6
1
2
3
4
5
6

output:

65
0 -5 1 -5 1 -4
3 -5 2 -5 2 -4
4 -5 5 -5 5 -4
7 -5 6 -5 6 -4
8 -5 9 -5 9 -4
11 -5 10 -5 10 -4
12 -5 13 -5 13 -4
15 -5 14 -5 14 -4
2 -4 3 -4 3 -3
5 -4 4 -4 4 -3
1 -4 2 -4 2 -3
6 -4 5 -4 5 -3
0 -4 1 -4 1 -3
7 -4 6 -4 6 -3
10 -4 11 -4 11 -3
13 -4 12 -4 12 -3
9 -4 10 -4 10 -3
14 -4 13 -4 13 -3
8 -4 9 ...

result:

ok Output is valid. OK

Extra Test:

score: 0
Extra Test Passed