結果

問題 No.2000 Distanced Characters
ユーザー outlineoutline
提出日時 2022-07-15 19:04:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 2,165 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 143,488 KB
実行使用メモリ 4,712 KB
最終ジャッジ日時 2023-09-09 21:32:47
合計ジャッジ時間 3,580 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 30 ms
4,380 KB
testcase_09 AC 340 ms
4,712 KB
testcase_10 AC 208 ms
4,472 KB
testcase_11 AC 42 ms
4,384 KB
testcase_12 AC 92 ms
4,376 KB
testcase_13 AC 80 ms
4,380 KB
testcase_14 AC 95 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string S;
    cin >> S;
    int n = S.length();
    vector D(26, vector<int>(26));
    for(int i = 0; i < 26; ++i){
        for(int j = 0; j < 26; ++j){
            cin >> D[i][j];
        }
    }
    vector<vector<int>> pos(26);
    for(int i = 0; i < n; ++i){
        pos[S[i] - 'a'].emplace_back(i);
    }
    vector ans(26, vector<bool>(26, true));
    for(int a = 0; a < 26; ++a){
        for(int i : pos[a]){
            for(int b = 0; b < 26; ++b){
                int idx = upper_bound(begin(pos[b]), end(pos[b]), i) - begin(pos[b]);
                if(idx == pos[b].size())    continue;
                int j = pos[b][idx];
                ans[a][b] = ans[a][b] & (D[a][b] <= j - i);
            }
        }
    }
    for(int i = 0; i < 26; ++i){
        for(int j = 0; j < 26; ++j){
            cout << (ans[i][j] ? "Y " : "N ");
        }
        cout << '\n';
    }

    return 0;
}
0