結果

問題 No.61 リベリオン
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-31 00:44:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 1,599 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 159,464 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:19:20
合計ジャッジ時間 1,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 44 ms
5,376 KB
testcase_04 AC 44 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getDir(int, int)’:
main.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int getDir(int x, int y) {
  if(x >= 0 && y >= 0) return 0;
  if(x >= 0 && y < 0)  return 1;
  if(x < 0 && y >= 0)  return 2;
  if(x < 0 && y < 0)   return 3;  
}

int main() {
  // ios_base::sync_with_stdio(false);
  int Q;
  cin >> Q;
  rep(i, Q) {
    int W, H, D, mx, my, hx, hy, vx, vy;
    cin >> W >> H >> D >> mx >> my >> hx >> hy >> vx >> vy;

    int d = __gcd(abs(vx), abs(vy));
    vx /= d;
    vy /= d;
    D *= d;
    
    bool visited[H + 1][W + 1][4];
    memset(visited, false, sizeof(visited));
    visited[hy][hx][getDir(vx, vy)] = true;
    
    rep(j, D) {
      int nx = hx + vx;
      int ny = hy + vy;
      while(nx < 0 || W < nx || ny < 0 || H < ny) {
        if(nx < 0) {
          vx *= -1;
          nx = abs(nx);
        }
        if(W < nx) {
          vx *= -1;
          nx = 2 * W - nx;
        }
        if(ny < 0) {
          vy *= -1;
          ny = abs(ny);
        }
        if(H < ny) {
          vy *= -1;
          ny = 2 * H - ny;
        }
      }
      if(visited[ny][nx][getDir(vx, vy)]) break;
      visited[ny][nx][getDir(vx, vy)] = true;

      hx = nx;
      hy = ny;
    }

    bool ans = false;
    rep(j, 4) ans |= visited[my][mx][j];
    cout << (ans ? "Hit" : "Miss") << endl;
  }
  return 0;
}
0