提出 #70429701


ソースコード 拡げる

#line 1 "main.cpp"
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vul = vector<ull>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vs = vector<string>;
template<class T> using pq = priority_queue<T,vector<T>, greater<T>>;
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(a,b,c,name,...) name
#define rep1(n) for (ll UNUSED_NUMBER = 0; UNUSED_NUMBER < (n); ++UNUSED_NUMBER)
#define rep2(i, n) for (ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n) - 1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n) - 1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (b) - 1;i >= (a);i--)
#define rrep4(i,a,b,c) for(ll i = (a) + (((b)-(a)-1) / (c) - (((b)-(a)-1) % (c) && (((b)-(a)-1) ^ c) < 0)) * (c);i >= (a);i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all1(i) begin(i) , end(i)
#define all2(i,a) begin(i) , begin(i) + a
#define all3(i,a,b) begin(i) + a , begin(i) + b
#define all(...) overload3(__VA_ARGS__, all3, all2, all1)(__VA_ARGS__)
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){return *min_element(all(a));}
template<class T> auto max(const T& a){return *max_element(all(a));}
template<class... Ts> void in(Ts&... t);
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define VEC(type, name, size) vector<type> name(size); in(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name)
ll intpow(ll a, ll b){ll ans = 1; while(b){if(b & 1) ans *= a; a *= a; b /= 2;} return ans;}
ll modpow(ll a, ll b, ll p){ ll ans = 1; a %= p;if(a < 0) a += p;while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
bool is_clamp(ll val,ll low,ll high) {return low <= val && val < high;}
void Yes() {cout << "Yes\n";return;}
void No() {cout << "No\n";return;}
void YES() {cout << "YES\n";return;}
void NO() {cout << "NO\n";return;}
template <typename U,typename T>
U floor(U a, T b) {return a / b - (a % b && (a ^ b) < 0);}
template <typename U,typename T>
U ceil(U x, T y) {return floor(x + y - 1, y);}
template <typename U,typename T>
T bmod(U x, T y) {return x - y * floor(x, y);}
template <typename U,typename T>
pair<U, T> divmod(U x, T y) {U q = floor(x, y);return {q, x - q * y};}
namespace IO{
#define VOID(a) decltype(void(a))
struct setting{ setting(){cin.tie(nullptr); ios::sync_with_stdio(false);fixed(cout); cout.precision(15);}} setting;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){in(get<idx>(t)...);}
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ituple(t, make_index_sequence<tuple_size<T>::value>{});} 
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO :: i(t)); }
#undef unpack
constexpr long double PI = 3.141592653589793238462643383279L;
template <class F> struct REC {
    F f;
    REC(F &&f_) : f(forward<F>(f_)) {}
    template <class... Args> auto operator()(Args &&...args) const { return f(*this, forward<Args>(args)...); }};

constexpr int mod = 998244353;
//constexpr int mod = 1000000007;


void solve() {
    INT(n,m);
    vvi g(n);
    rep(i,m) {
        INT(u,v);
        u--,v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    STR(s);
    vvi d(2,vi(n,1e9)),from(2,vi(n,-1));
    queue<pii> q;
    rep(i,n) {
        if(s[i] == 'S') {
            q.emplace(0,i);
            d[0][i] = 0;
            from[0][i] = i;
        }
    }
    while(!q.empty()) {
        auto [id,now] = q.front();
        q.pop();
        for(auto &nex:g[now]) {
            if(chmin(d[0][nex],d[id][now] + 1)) {
                q.emplace(0,nex);
                from[0][nex] = from[id][now];
            }
            else if(from[0][nex] != from[id][now] && chmin(d[1][nex],d[id][now] + 1)) {
                q.emplace(1,nex);
                from[1][nex] = from[id][now];
            }
        }
    }
    rep(i,n) {
        if(s[i] == 'D') {
            cout << d[0][i] + d[1][i] << '\n';
        }
    }
}       



int main() {
    //INT(TT);
    int TT = 1;
    rep(i,TT) solve();
}

提出情報

提出日時
問題 E - Hit and Away
ユーザ siganai
言語 C++ 20 (gcc 12.2)
得点 450
コード長 5628 Byte
結果 AC
実行時間 71 ms
メモリ 20608 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 54
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3540 KiB
example_01.txt AC 1 ms 3608 KiB
hand_00.txt AC 69 ms 18184 KiB
hand_01.txt AC 64 ms 18376 KiB
hand_02.txt AC 56 ms 19532 KiB
hand_03.txt AC 49 ms 20608 KiB
hand_04.txt AC 50 ms 19816 KiB
hand_05.txt AC 18 ms 6260 KiB
hand_06.txt AC 19 ms 5908 KiB
hand_07.txt AC 66 ms 18152 KiB
hand_08.txt AC 41 ms 12584 KiB
hand_09.txt AC 17 ms 5252 KiB
hand_10.txt AC 56 ms 18072 KiB
hand_11.txt AC 50 ms 18156 KiB
hand_12.txt AC 51 ms 18140 KiB
hand_13.txt AC 48 ms 18792 KiB
hand_14.txt AC 46 ms 20572 KiB
hand_15.txt AC 49 ms 20532 KiB
random_00.txt AC 68 ms 18328 KiB
random_01.txt AC 68 ms 18384 KiB
random_02.txt AC 67 ms 18308 KiB
random_03.txt AC 68 ms 18332 KiB
random_04.txt AC 68 ms 18308 KiB
random_05.txt AC 68 ms 18276 KiB
random_06.txt AC 65 ms 18032 KiB
random_07.txt AC 65 ms 18104 KiB
random_08.txt AC 64 ms 18000 KiB
random_09.txt AC 69 ms 18020 KiB
random_10.txt AC 67 ms 18024 KiB
random_11.txt AC 68 ms 18168 KiB
random_12.txt AC 65 ms 18100 KiB
random_13.txt AC 66 ms 18088 KiB
random_14.txt AC 65 ms 18096 KiB
random_15.txt AC 69 ms 18116 KiB
random_16.txt AC 68 ms 18036 KiB
random_17.txt AC 68 ms 18080 KiB
random_18.txt AC 11 ms 4492 KiB
random_19.txt AC 13 ms 4864 KiB
random_20.txt AC 16 ms 5568 KiB
random_21.txt AC 15 ms 5452 KiB
random_22.txt AC 14 ms 5240 KiB
random_23.txt AC 12 ms 4648 KiB
random_24.txt AC 34 ms 6820 KiB
random_25.txt AC 30 ms 6804 KiB
random_26.txt AC 31 ms 6776 KiB
random_27.txt AC 28 ms 6928 KiB
random_28.txt AC 35 ms 7200 KiB
random_29.txt AC 30 ms 6688 KiB
random_30.txt AC 71 ms 17224 KiB
random_31.txt AC 49 ms 13136 KiB
random_32.txt AC 59 ms 13460 KiB
random_33.txt AC 61 ms 18584 KiB
random_34.txt AC 56 ms 12420 KiB
random_35.txt AC 55 ms 13412 KiB