提出 #44458920


ソースコード 拡げる

// clang-format off
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__)
#define _RREP(i,n) RREPI(i,n,0)
#define RREPI(i,a,b) for(int i=int(a);i>=int(b);--i)
#define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
typedef long long ll;
const int INF32 = 1001001001;
const long long INF64 = 1001001001001001001;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }} init;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<class T> T gcd(T x, T y){ return (x % y) ? gcd(y, x % y) : y; }
template<class T> T lcm(T x, T y){ return x / gcd(x, y) * y; }
template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T> void output(vector<T> v) { for (auto u : v) cout << u << ' '; cout << '\n'; };
void yesno(bool is_ok) { cout << (is_ok ? "yes" : "no") << '\n'; }
void YesNo(bool is_ok) { cout << (is_ok ? "Yes" : "No") << '\n'; }
void YESNO(bool is_ok) { cout << (is_ok ? "YES" : "NO") << '\n'; }

// clang-format on
int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> to(n);
    REP(i, n - 1) {
        if (s[i] == 'A') {
            to[i].push_back(i + 1);
        } else {
            to[i + 1].push_back(i);
        }
    }
    vector<int> dist(n, -1);
    auto dfs = [&](auto &dfs, int v) -> void {
        if (dist[v] == -1) {
            dist[v] = 1;
        }
        for (int u : to[v]) {
            if (chmax(dist[u], dist[v] + 1)) {
                dfs(dfs, u);
            }
        }
    };
    REP(i, n) { dfs(dfs, i); }
    int ans = 0;
    REP(i, n) ans += dist[i];
    output(ans);
}

提出情報

提出日時
問題 B38 - Heights of Grass
ユーザ noko206
言語 C++ (GCC 9.2.1)
得点 1000
コード長 2229 Byte
結果 AC
実行時間 7 ms
メモリ 3708 KiB

コンパイルエラー

./Main.cpp: In instantiation of ‘void output(const T&, const Ts& ...) [with T = int; Ts = {}]’:
./Main.cpp:59:15:   required from here
./Main.cpp:26:86: warning: statement has no effect [-Wunused-value]
   26 | template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                      ^~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 1000 / 1000
結果
AC × 1
AC × 16
セット名 テストケース
Sample sample_01.txt
All rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_06.txt, rand_07.txt, rand_08.txt, rand_09.txt, rand_10.txt, rand_11.txt, rand_12.txt, rand_13.txt, rand_14.txt, rand_15.txt, sample_01.txt
ケース名 結果 実行時間 メモリ
rand_01.txt AC 6 ms 3644 KiB
rand_02.txt AC 2 ms 3580 KiB
rand_03.txt AC 4 ms 3644 KiB
rand_04.txt AC 5 ms 3608 KiB
rand_05.txt AC 4 ms 3580 KiB
rand_06.txt AC 3 ms 3636 KiB
rand_07.txt AC 2 ms 3684 KiB
rand_08.txt AC 4 ms 3512 KiB
rand_09.txt AC 3 ms 3620 KiB
rand_10.txt AC 4 ms 3632 KiB
rand_11.txt AC 7 ms 3624 KiB
rand_12.txt AC 3 ms 3664 KiB
rand_13.txt AC 3 ms 3688 KiB
rand_14.txt AC 2 ms 3528 KiB
rand_15.txt AC 4 ms 3708 KiB
sample_01.txt AC 2 ms 3496 KiB