結果

問題 No.5025 Forest Fire
コンテスト
ユーザー UT0911
提出日時 2026-10-19 22:57:15
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 327µs
コード長 7,367 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,399 ms
コンパイル使用メモリ 402,296 KB
実行使用メモリ 9,928 KB
スコア 148,596,922
最終ジャッジ日時 2026-10-24 14:32:29
合計ジャッジ時間 59,542 ms
ジャッジサーバーID
(参考情報)
judge1_0 / <nil>
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// Library : https://github.com/UT0911/UTLibrary

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using Graph = vector<vector<pair<ll, int>>>;
#define ALL(x) (x).begin(), (x).end()
#define coutY cout << "Yes" << endl;
#define coutN cout << "No" << endl;
#define arrIn(arr, start, N)         \
  for (ll i = (start); i < (N); ++i) \
    cin >> arr[i];
#define arrOut(arr, start, N)        \
  for (ll i = (start); i < (N); ++i) \
  {                                  \
    cout << arr[i];                  \
    if (i == (N) - 1)                \
      cout << endl;                  \
    else                             \
      cout << " ";                   \
  }
#define UNIQUE(A) \
  sort(ALL(A));   \
  A.erase(unique(ALL(A)), A.end());
const int mod9 = 998244353;
const int mod1 = 1000000007;
const int intM = numeric_limits<int>::max();
const ll llM = numeric_limits<ll>::max();
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string abc = "abcdefghijklmnopqrstuvwxyz";
vi dx = {0, 1, 0, -1};
vi dy = {-1, 0, 1, 0};
vi ddx = {-1, 0, 1, -1, 1, -1, 0, 1};
vi ddy = {-1, -1, -1, 0, 0, 1, 1, 1};

void yn(bool tf) { cout << (tf ? "Yes" : "No") << endl; }
void YN(bool tf) { cout << (tf ? "YES" : "NO") << endl; }

template <class T>
using priority_queueR = priority_queue<T, vector<T>, greater<T>>;

// cout << fixed << setprecision(20) <<

void arrOut2(auto A)
{
  for (auto x : A)
  {
    for (auto y : x)
    {
      cout << y << " ";
    }
    cout << endl;
  }
}

bool kaibun(string S)
{
  string T = S;
  reverse(ALL(S));
  return S == T;
}

int ketawa(int x)
{
  string S = to_string(x);
  int sum = 0;
  int len = S.size();
  for (int i = 0; i < len; i++)
  {
    sum += (int)(S[i] - '0');
  }
  return sum;
}

ll Power(ll a, ll b, ll m)
{
  ll ans = 1, p = a;
  for (ll i = 0; i < 60; i++)
  {
    if (b & (1LL << i))
    {
      ans = (ans * p) % m;
    }
    p = (p * p) % m;
  }
  return ans;
}

ll ncr(ll n, ll r, ll m)
{
  if (r <= 0 || r > n)
    return 0;
  ll bunshi = 1;
  for (ll i = 1; i <= n; i++)
    bunshi = (bunshi * i) % m;

  ll bunbo = 1;
  for (ll i = 1; i <= r; i++)
    bunbo = (bunbo * i) % m;
  for (ll i = 1; i <= n - r; i++)
    bunbo = (bunbo * i) % m;

  return (bunshi * Power(bunbo, m - 2, m)) % m;
}

vector<vector<int>> BFS(int H, int W, vector<string> S, int sh, int sw)
{
  vector<vector<int>> visited(H, vector<int>(W, intM));
  queue<tuple<int, int, int>> q;
  visited[sh][sw] = 0;
  q.push({0, sh, sw});
  while (!q.empty())
  {
    auto [w, nowH, nowW] = q.front();
    q.pop();
    for (int i = 0; i < 4; i++)
    {
      int nextH = nowH + dy[i];
      int nextW = nowW + dx[i];
      if (0 <= nextH && nextH < H && 0 <= nextW && nextW < W && S[nextH][nextW] != '#' && visited[nextH][nextW] == intM)
      {
        visited[nextH][nextW] = w + 1;
        q.push({w + 1, nextH, nextW});
      }
    }
  }

  return visited;
}

vector<vector<int>> BFS2(int H, int W, vector<string> h, vector<string> v, int sh, int sw)
{
  vector<vector<int>> visited(H, vector<int>(W, intM));
  queue<tuple<int, int, int>> q;
  visited[sh][sw] = 0;
  q.push({0, sh, sw});
  while (!q.empty())
  {
    auto [w, nowH, nowW] = q.front();
    q.pop();
    for (int i = 0; i < 4; i++)
    {
      int nextH = nowH + dy[i];
      int nextW = nowW + dx[i];
      if (0 <= nextH && nextH < H && 0 <= nextW && nextW < W && ((i % 2 == 0 && h[min(nowH, nextH)][nextW] == '0') || (i % 2 == 1 && v[nextH][min(nowW, nextW)] == '0')) && visited[nextH][nextW] == intM)
      {
        visited[nextH][nextW] = w + 1;
        q.push({w + 1, nextH, nextW});
      }
    }
  }

  return visited;
}

vector<ll> Dijkstra(int N, const Graph &edge, int s)
{
  vector<ll> dist(N + 1, llM);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
  dist[s] = 0LL;
  q.push({0LL, s});
  while (!q.empty())
  {
    auto [w, now] = q.top();
    q.pop();
    if (w != dist[now])
      continue;
    for (pair<ll, int> nextEdge : edge[now])
    {
      int next = nextEdge.second;
      ll nextW = w + nextEdge.first;
      if (dist[next] > nextW)
      {
        dist[next] = nextW;
        q.push({nextW, next});
      }
    }
  }
  return dist;
}

template <typename T, typename U>
vector<T> Imos(U N, U M, vector<U> L, vector<U> R, vector<T> W)
{
  vector<T> A(N + 2, 0);
  for (int i = 0; i < M; i++)
  {
    A[L[i]] += W[i];
    A[R[i] + 1] -= W[i];
  }

  for (int i = 1; i <= N; i++)
  {
    A[i] += A[i - 1];
  }

  return A;
}

template <typename T, typename U>
vector<vector<T>> Imos2(U N, U M, U K, vector<U> r1, vector<U> c1, vector<U> r2, vector<U> c2, vector<T> W)
{
  vector<vector<T>> A(N + 2, vector<T>(M + 2, 0));
  for (int i = 0; i < K; i++)
  {
    A[r1[i]][c1[i]] += W[i];
    A[r2[i] + 1][c2[i] + 1] += W[i];
    A[r1[i]][c2[i] + 1] -= W[i];
    A[r2[i] + 1][c1[i]] -= W[i];
  }

  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= M; j++)
    {
      A[i][j] += A[i - 1][j];
    }
  }

  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= M; j++)
    {
      A[i][j] += A[i][j - 1];
    }
  }

  return A;
}

template <typename T, typename U>
vector<T> PrefixSum(U N, vector<T> A)
{
  vector<T> ruiseki(N + 1, 0);
  for (int i = 1; i <= N; i++)
  {
    ruiseki[i] = ruiseki[i - 1] + A[i];
  }
  return ruiseki;
}

template <typename T, typename U>
vector<vector<T>> PrefixSum2(U N, U M, vector<vector<T>> A)
{
  vector<vector<T>> ruiseki(N + 1, vector<T>(M + 1, 0));
  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= M; j++)
    {
      ruiseki[i][j] = A[i][j];
    }
  }

  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= M; j++)
    {
      ruiseki[i][j] += ruiseki[i - 1][j];
    }
  }

  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= M; j++)
    {
      ruiseki[i][j] += ruiseki[i][j - 1];
    }
  }

  return ruiseki;
}

random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dist(0, 2000000000);

int rnd(int MIN, int MAX)
{
  return MIN + dist(gen) % (MAX - MIN + 1);
}

// auto start = high_resolution_clock::now();

// ll getTime(){
//   auto end = high_resolution_clock::now();
//   return  duration_cast<milliseconds>(end - start).count();
// }

// bool CheckTime(auto limit,auto eps){
//   return  getTime()<limit-eps;
// }

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
  ifstream in("a_input.txt");
  cin.rdbuf(in.rdbuf());
#endif
  int N, K;
  cin >> N >> K;
  vs d(N);
  vvi dNum(N, vi(N));
  for (int i = 0; i < N; i++)
  {
    cin >> d[i];
    for (int j = 0; j < N; j++)
    {
      dNum[i][j] = (int)(d[i][j] - '0');
    }
  }

  int cn = 0;
  vi cutI, cutJ;
  for (int i = 0; i < N; i++)
  {
    if (dNum[N / 2][i] != 0)
    {
      cutI.push_back(N / 2);
      cutJ.push_back(i);
    }
    if (dNum[i][N / 2] != 0 && N / 2 != i)
    {
      cutI.push_back(i);
      cutJ.push_back(N / 2);
    }
  }

  cout << cutI.size() << endl;
  for (int i = 0; i < cutI.size(); i++)
  {
    cout << cutI[i] << " " << cutJ[i] << endl;
  }

  return 0;
}
0