結果

問題 No.202 1円玉投げ
ユーザー yuppe19 😺
提出日時 2020-01-18 11:11:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 1,380 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 200,552 KB
最終ジャッジ日時 2025-01-08 19:57:33
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
main.cpp:16:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     int x, y; scanf("%d%d", &x, &y);
      |               ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Point = pair<int, int>;

int main(void) {
  const int M = 20001;
  const int LEN = 33;
  const int CNT = M / LEN;
  int res = 0;
  // 33 x 33の長さの正方形で区画を作る
  // 区画それぞれはvector<Point>にしておいて、点を追加できるようにする
  // vector<Point>の二次元配列なので、vector<vector<vector<Point>>>になる
  vector<vector<vector<Point>>> blocks(CNT+1, vector<vector<Point>>(CNT+1));
  int n; scanf("%d", &n);
  for(int i=0; i<n; i++) {
    int x, y; scanf("%d%d", &x, &y);
    int px = x / LEN, py = y / LEN;
    bool ok = true;
    // 区画とその周囲だけをチェックする
    for(int xx=-1; xx<=1; xx++) {
      for(int yy=-1; yy<=1; yy++) {
        int nx = px + xx;
        int ny = py + yy;
        if(nx < 0 || CNT < nx || ny < 0 || CNT < ny) { continue; }
        for(size_t k=0; k<blocks[nx][ny].size(); k++) {
          Point p = blocks[nx][ny][k];
          // 重なっていたらフラグを折って抜ける
          if((p.first-x)*(p.first-x) + (p.second-y)*(p.second-y) < 400) {
            ok = false;
            break;
          }
        }
      }
    }
    if(ok) {
      res++;
      // 区画の点リスト(vector<Point>)に点を入れる
      blocks[px][py].push_back(Point(x, y));
    }
  }
  printf("%d\n", res);
  return 0;
}
0