답안 #212282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212282 2020-03-22T16:33:53 Z model_code Trener (COCI20_trener) C++17
110 / 110
190 ms 12172 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

const int MAXN = 55;
const int MAXK = 1505;
const int MAXM = MAXN * MAXK;

const int MOD = 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}

int mul(int a, int b) {
  return (ll)a * b % MOD;
}

int n, k;
int cnt[MAXM], dp[MAXM];

unordered_map <string, int> ime;
int IME;

vector <int> v[MAXM];
string s;

int rek(int cvor) {
  if (dp[cvor] != -1) return dp[cvor];
  int ret = 0;
  sort(all(v[cvor]));
  REP(i, (int)v[cvor].size()) {
    int ncvor = v[cvor][i];
    if (i && v[cvor][i - 1] == ncvor) continue;
    ret = add(ret, mul(cnt[cvor], rek(ncvor)));
  }
  return dp[cvor] = ret;
}

int main() {
  scanf("%d %d",&n,&k);
  memset(dp, -1, sizeof dp);
  REP(i, n) {
    REP(j, k) {
      cin >> s;
      if (!ime.count(s)) {
        ime[s] = ++IME;
      }
      int cvor = ime[s];
      cnt[cvor]++;
      if (i == n - 1) dp[cvor] = cnt[cvor];

      if (i) {
        REP(start, 2) {
          string t = s.substr(start, i);
          if (ime.count(t)) {
            v[ime[t]].pb(cvor);
          }
        }
      } else {
        if (cnt[cvor] == 1) {
          v[n * k + 1].pb(cvor);
        }
      }
    }
  }

  cnt[n * k + 1] = 1;
  printf("%d\n",rek(n * k + 1));
  return 0;
}

Compilation message

trener.cpp: In function 'int main()':
trener.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&n,&k);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Correct 6 ms 2560 KB Output is correct
4 Correct 6 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3200 KB Output is correct
2 Correct 17 ms 3200 KB Output is correct
3 Correct 16 ms 3200 KB Output is correct
4 Correct 14 ms 2688 KB Output is correct
5 Correct 16 ms 3200 KB Output is correct
6 Correct 17 ms 3072 KB Output is correct
7 Correct 15 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Correct 6 ms 2560 KB Output is correct
4 Correct 6 ms 2560 KB Output is correct
5 Correct 16 ms 3200 KB Output is correct
6 Correct 17 ms 3200 KB Output is correct
7 Correct 16 ms 3200 KB Output is correct
8 Correct 14 ms 2688 KB Output is correct
9 Correct 16 ms 3200 KB Output is correct
10 Correct 17 ms 3072 KB Output is correct
11 Correct 15 ms 2688 KB Output is correct
12 Correct 177 ms 12172 KB Output is correct
13 Correct 184 ms 12164 KB Output is correct
14 Correct 180 ms 12168 KB Output is correct
15 Correct 176 ms 12168 KB Output is correct
16 Correct 129 ms 3324 KB Output is correct
17 Correct 165 ms 9772 KB Output is correct
18 Correct 186 ms 10024 KB Output is correct
19 Correct 190 ms 9772 KB Output is correct
20 Correct 165 ms 9768 KB Output is correct
21 Correct 167 ms 9768 KB Output is correct
22 Correct 137 ms 3448 KB Output is correct