結果

問題 No.471 直列回転機
ユーザー しらっ亭しらっ亭
提出日時 2016-12-21 01:12:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,583 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 179,132 KB
実行使用メモリ 24,420 KB
平均クエリ数 19595.66
最終ジャッジ日時 2023-09-23 12:03:34
合計ジャッジ時間 22,553 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,688 KB
testcase_01 AC 26 ms
24,408 KB
testcase_02 AC 26 ms
24,288 KB
testcase_03 AC 24 ms
24,420 KB
testcase_04 AC 27 ms
24,408 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 28 ms
24,408 KB
testcase_17 AC 24 ms
23,700 KB
testcase_18 AC 23 ms
23,676 KB
testcase_19 AC 26 ms
24,396 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 27 ms
23,568 KB
testcase_53 AC 30 ms
24,336 KB
testcase_54 AC 29 ms
23,664 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;
using vb=vector<bool>;using vs=vector<string>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){o<<'('<<p.fst<<", "<<p.snd<<')';return o;}

const double EPS = 1e-9;

typedef vector<ll> Vec;
typedef vector<Vec> Mat;

Vec gauss_jordan(const Mat& A, const Vec& b) {
  assert(A.size() == A[0].size());
  const int n = A.size();
  Mat B(n, Vec(n + 1));

  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) B[i][j] = A[i][j];
  for (int i = 0; i < n; i++) B[i][n] = b[i];

  for (int i = 0; i < n; i++) {
    int pivot = i;
    for (int j = i; j < n; j++) if (abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
    swap(B[i], B[pivot]);

    if (abs(B[i][i]) <= EPS) return Vec();

    for (int j = i + 1; j <= n; j++) B[i][j] /= B[i][i];
    for (int j = 0; j < n; j++) {
      if (i != j) {
        for (int k = i + 1; k <= n; k++) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }

  Vec x(n);
  for (int i = 0; i < n; i++) x[i] = B[i][n];
  return x;
}

using point = complex<ll>;

int m;
vector<point> P;

point query(const point& p) {
  _p("? %lld %lld\n", p.real(), p.imag());
  fflush(stdout);
  ll x, y;
  scanf("%lld%lld", &x, &y);
  return {x, y};
}

void Main() {
  scanf("%d", &m);
  rep(i, m) {
    int x, y;
    scanf("%d%d", &x, &y);
    P.emplace_back(x, y);
  }

  int q = min(m, 10);

  vector<point> Q(q);
  rep(i, q) {
    Q[i] = query(P[i]);
  }

  /*
  */
  if (m <= 10) {
    _p("!\n");
    fflush(stdout);
    forr(p, Q) {
      _p("%lld %lld\n", p.real(), p.imag());
      fflush(stdout);
    }
    return;
  }

  rep(i, m) rep(j, i+1, m) rep(k, j+1, m) {
    Mat a = {
      {P[i].real(), P[i].imag(), 1},
      {P[j].real(), P[j].imag(), 1},
      {P[k].real(), P[k].imag(), 1},
    };
    Vec b1 = {Q[i].real(), Q[j].real(), Q[k].real()};
    Vec b2 = {Q[i].imag(), Q[j].imag(), Q[k].imag()};
    Vec b3 = {1, 1, 1};

    Vec x1 = gauss_jordan(a, b1);
    Vec x2 = gauss_jordan(a, b2);
    Vec x3 = gauss_jordan(a, b3);

    if (sz(x1) && sz(x2) && sz(x3)) {
      vector<point> ans;
      bool ok = 1;
      forr(p, P) {
        ll nx = x1[0] * p.real() + x1[1] * p.imag() + x1[2];
        ll ny = x2[0] * p.real() + x2[1] * p.imag() + x2[2];
        ll nz = x3[0] * p.real() + x3[1] * p.imag() + x3[2];
        if (nz != 1) {
          ok = false;
          continue;
        }
        ans.emplace_back(nx, ny);
      }
      if (ok) {
        _p("!\n");
        fflush(stdout);
        forr(p, ans) {
          _p("%lld %lld\n", p.real(), p.imag());
          fflush(stdout);
        }
        return;
      }
    }
  }
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }
0