結果

問題 No.455 冬の大三角
ユーザー k
提出日時 2020-07-10 13:25:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 197,216 KB
最終ジャッジ日時 2025-01-11 17:23:54
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

bool check(const vector<int> &x, const vector<int> &y) {
  int x1 = x[1] - x[0], x2 = x[2] - x[0];
  int y1 = y[1] - y[0], y2 = y[2] - y[0];
  return x1 * y2 - y1 * x2 != 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, w;
  cin >> h >> w;
  vector<string> bd(h);
  REP (i, h) cin >> bd[i];

  vector<int> y, x;
  REP (i, h) REP (j, w) if (bd[i][j] == '*') {
    y.push_back(i);
    x.push_back(j);
  }

  REP (i, h) REP (j, w) {
    if (bd[i][j] == '*' || x.size() >= 3) continue;
    y.push_back(i);
    x.push_back(j);
    if (!check(x, y)) {
      y.pop_back();
      x.pop_back();
    }
  }

  bd[y.back()][x.back()] = '*';

  REP (i, h)
    cout << bd[i] << endl;
  
  return 0;
}
0