結果

問題 No.2000 Distanced Characters
ユーザー WONDER0WONDER0
提出日時 2022-07-08 23:10:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 3,400 bytes
コンパイル時間 3,281 ms
コンパイル使用メモリ 216,092 KB
実行使用メモリ 5,700 KB
最終ジャッジ日時 2023-08-27 23:01:14
合計ジャッジ時間 3,109 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 8 ms
5,388 KB
testcase_09 AC 7 ms
5,700 KB
testcase_10 AC 10 ms
5,404 KB
testcase_11 AC 8 ms
5,340 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 7 ms
4,560 KB
testcase_14 AC 6 ms
4,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define rep2(i, n) for(ll i = 0; n; i++)
#define rep3(i,s,n) for(ll i = (s); i < (n); i++)
#define rep4(i,s,n) for(ll i = (s); n; i++)
#define repe(v, V) for(auto& v: V)
#define all(x) (x).begin(),(x).end()
#define v vector
#define mod(a,b) (((a) % (b) + (b)) % (b)) /* 負の数に対応した剰余 */
#define pi 3.14159265358979
#define eps 1e-13
#define inf 1000000007
#define MAX_LL 9223372036854775807
using namespace std;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int to_base10(string Nx, int base)  /* N進数から10進数に変換 */ { int N10 = 0; rep(i, Nx.length()) N10 += stoll(Nx.substr(Nx.length() - 1 - i, 1)) * pow(base, i); return N10; }
string to_baseN(int N10, int base, int min_digits = 1)  /* 10進数からN進数に変換 */ { string r; while (N10 != 0) { r = to_string(N10 % base) + r; N10 /= base; } while (r.length() < min_digits) r = "0" + r; return r; }
v<pair<int, int>> prime_factorize(int N) /* 素因数分解 .first: 素数, .second: 指数 */ { v<pair<int, int>> res; rep4(a, 2, a * a <= N) { if (N % a != 0) continue; int ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; }
v<int> divisors(int N)/*約数列挙*/ {v<int> r;rep4(i, 1, i * i <= N) {if (N % i == 0) {r.push_back(i);if(i != N / i) r.push_back(N / i);}}return r;}
int modinv(int a, int m)/*逆元*/ {	int b = m, u = 1, v = 0;while (b) {	long long t = a / b;a -= t * b; swap(a, b);	u -= t * v; swap(u, v);	}u %= m;if (u < 0) u += m;	return u;}
int sigma(int a, int b)/*a,a+1,...,bの総和*/ {return b * (b + 1) / 2 - a * (a - 1) / 2;}
v<v<int>> Pascal(int N, int mod = MAX_LL)/*パスカルの三角形(nCk=v[n][k]) O(N^2)*/ { v<v<int>> com(N + 1,v<int>(N + 1)); com[0][0] = 1; for (int i = 1; i < N + 1; ++i) { com[i][0] = 1; for (int j = 1; j < N + 1; j++) { com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % mod; } }return com; }
int Pow(int n, int p, int mod = MAX_LL)/* 指数関数のLL版(繰り返し2乗法) modあり */ {int ans = 1;int now = n;for (; p > 0; p >>= 1){if ((p & 1) == 1){ans *= now;ans %= mod;}now *= now;now %= mod;}return ans;}
void printVec(const vector<int>& vec)/* vectorの中身をprint */ {cout << "";for (auto it = vec.begin(); it != vec.end(); ++it) {cout << *it << " ";	}	cout << endl;}
void makeset(v<int>& vec)/* vectorをソートし、重複要素を削除*/ { sort(vec.begin(), vec.end());	vec.erase(unique(vec.begin(), vec.end()), vec.end());}

string S;
v<v<int>> D(26, v<int>(26, 0));
int N, M;

signed main()
{
	cout << setprecision(15);

	cin >> S;

	rep(i, 26) {
		rep(j, 26) {
			cin >> D[i][j];
		}
	}

	v<v<int>> cnt(26);
	rep(i, S.length()) {
		cnt[S[i] - 'a'].push_back(i);
	}

	bool flag = false;

	rep(i, 26) {
		rep(j, 26) {
			flag = false;
			if (cnt[i].size() == 0 || cnt[j].size() == 0 || D[i][j] <= 1) {
				cout << "Y ";
				continue;
			}
			repe(x, cnt[i]) {
				auto it1 = lower_bound(all(cnt[j]), x + D[i][j]) - cnt[j].begin();
				auto it2 = lower_bound(all(cnt[j]), x + 1) - cnt[j].begin();
				if (it1 - it2 > 0) {
					cout << "N ";
					flag = true;
					break;
				}
			}
			if (!flag) cout << "Y ";
		}
		cout << endl;
	}

}
0