結果

問題 No.1512 作文
ユーザー wait_sushiwait_sushi
提出日時 2021-05-21 21:36:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 4,625 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 178,516 KB
実行使用メモリ 50,412 KB
最終ジャッジ日時 2024-04-18 14:53:32
合計ジャッジ時間 4,161 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 59 ms
27,096 KB
testcase_05 AC 58 ms
26,944 KB
testcase_06 AC 59 ms
27,088 KB
testcase_07 AC 58 ms
26,952 KB
testcase_08 AC 58 ms
27,064 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 5 ms
6,940 KB
testcase_19 AC 5 ms
6,944 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 102 ms
50,412 KB
testcase_41 AC 103 ms
50,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void cl(T& ...)’:
main.cpp:71:59: warning: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’
   71 | template <class... T> void cl(T &... t) { (..., (t.clear())); }
      |                                                           ^
main.cpp: In function ‘void in(T& ...)’:
main.cpp:72:58: warning: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’
   72 | template <class... T> void in(T &... t) { (..., (cin >> t)); }
      |                                                          ^

ソースコード

diff #

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (ll i = 0; i < n; ++i)
#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; i--;)
#define rrep2(i, n) for (ll i = n; i--;)
#define rrep3(i, a, b) for (ll i = b; i-- > (a);)
#define rrep4(i, a, b, c)                                                      \
  for (ll i = (a) + ((b) - (a)-1) / (c) * (c); i >= (a); i -= c)
#define rrep(...)                                                              \
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define elif else if
ll beki(ll i) { return 1ll << i; }
#define skip(M)                                                                \
  if (M)                                                                       \
  continue
#define all(v) v.begin(), v.end()
#define allm(x, y, M) for (auto [(x), (y)] : (M))
#define alls(i, S) for (auto(&i) : (S))
#define pb push_back
#define fi first
#define se second
#define outno                                                                  \
  print("NO");                                                                 \
  return
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MAX_N1 = 200010;
const ll MAX_N2 = 500010;
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
  for (ll i : x) {
    cout << i << " ";
  }
  cout << endl;
}
void print(vector<PP> x) {
  for (PP i : x) {
    cout << i.first << " " << i.second << endl;
  }
  cout << endl;
}
template <class X> int lbound(vector<X> &Y, X a) {
  return lower_bound(all(Y), a) - Y.begin();
}
template <class X> int ubound(vector<X> &Y, X a) {
  return upper_bound(all(Y), a) - Y.begin();
}
template <class X> X lbound2(vector<X> &Y, X a, int mode = 0) {
  int x = lbound(Y, a) - mode;
  if (x < 0 || x >= Y.size())
    return INF;
  return Y[x];
}
template <class X> X ubound2(vector<X> &Y, X a, int mode = 0) {
  int x = ubound(Y, a) - mode;
  if (x < 0 || x >= Y.size())
    return INF;
  return Y[x];
}
template <class... T> void cl(T &... t) { (..., (t.clear())); }
template <class... T> void in(T &... t) { (..., (cin >> t)); }
template <class... T> void put(vl &V, int n, int mode = 0) {
  ll k;
  if (mode == 0)
    cl(V);
  rep(i, n) {
    cin >> k;
    V.pb(k);
  }
}
int max_index(vl &V) { return max_element(all(V)) - V.begin(); }
int min_index(vl &V) { return min_element(all(V)) - V.begin(); }
ll sum(vl &V) { return accumulate(all(V), 0ll); }
template <typename T> void UNIQUE(vector<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <typename T> T ADD(T a, T b) {
  T res;
  return __builtin_add_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}
template <typename T> T MUL(T a, T b) {
  T res;
  return __builtin_mul_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
};
template <typename T> T POW(T a, int n) {
  T res = 1;
  for (; n > 0; n >>= 1, a *= a)
    if (n & 1)
      res *= a;
  return res;
}
template <class X> bool ma(X &a, X b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class X> bool mi(X &a, X b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void vset(vl &A, ll n, ll k) { A = vl(n, k); }
void so(vl &A) { sort(all(A)); }
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, m, u, v;
ll codeforces = 1;
string S, T, U;
vl A, B, C, D;
vector<PP> VP, VP2;
set<ll> s1, s2;
void solve() {
  in(n);
  vector<string> VS;
  rep(n) {
    in(S);
    x = S.length();
    a = 1;
    rep(j, x - 1) {
      if (S[j] > S[j + 1])
        a = 0;
    }
    if (a)
      VS.pb(S);
  }
  sort(all(VS));
  n = VS.size();
  ll dp[n + 1][26];
  rep(i, n + 1) {
    rep(j, 26) { dp[i][j] = 0; }
  }
  rep(i, n) {
    rep(j, 26) {
      if (i)
        ma(dp[i][j], dp[i - 1][j]);
      if (j)
        ma(dp[i][j], dp[i][j - 1]);
      if (j <= VS[i][0] - 'a')
        ma(dp[i + 1][VS[i].back() - 'a'], dp[i][j] + ll(VS[i].length()));
      // print({i, j, dp[i][j]});
    }
  }
  rep(i, 26) ma(ans, dp[n][i]);
  print(ans);
}
int main() {
  // cout << fixed << setprecision(15);
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cin >> codeforces;
  while (codeforces--) {
    solve();
  }
}
0