結果

問題 No.2000 Distanced Characters
ユーザー bonKotsubonKotsu
提出日時 2022-08-03 21:10:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 4,617 ms
コンパイル使用メモリ 261,788 KB
実行使用メモリ 4,664 KB
最終ジャッジ日時 2023-10-11 16:09:58
合計ジャッジ時間 6,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 15 ms
4,444 KB
testcase_09 AC 271 ms
4,664 KB
testcase_10 AC 135 ms
4,588 KB
testcase_11 AC 25 ms
4,372 KB
testcase_12 AC 62 ms
4,348 KB
testcase_13 AC 54 ms
4,348 KB
testcase_14 AC 66 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

int main() {
  string s;
  cin >> s;
  vector d(26, vector<int>(26));
  rep(i,26)rep(j,26) cin >> d[i][j];
  vector<int> pos[26];
  rep(i,s.size()) {
    pos[s[i]-'a'].pb(i);
  }
  const int INF = 1001001001;
  vector dmin(26,vector<int>(26, INF));
  rep(i,26)rep(j,26) {
    if (i == j) {
      rep(k,(int)pos[i].size()-1) {
        chmin(dmin[i][i], pos[i][k+1]-pos[i][k]);
      }
    } else {
      for (auto x : pos[i]) {
        auto it = lower_bound(all(pos[j]), x);
        if (it != pos[j].end()) chmin(dmin[i][j], abs(x-*it));
      }
    }
  }
  rep(i,26){ 
    rep(j,26) {
      if (d[i][j] <= dmin[i][j]) cout << "Y" << " ";
      else cout << "N" << " ";
    }
    cout << endl;
  } 



  return 0;
}
0