Submission #38394170


Source Code Expand

#include <iostream>
#define N 510000
using namespace std;
int rt, ch[N][26], sum[N], tot;
void insert(int &x, int d, const char *c) {
  if (!x)
    x = ++tot;
  sum[x]++;
  if (!*c)
    return;
  insert(ch[x][*c - 'a'], d + 1, c + 1);
}
int query(int x, int d, const char *c) {
  if (sum[x] < 2)
    return 0;
  if (!*c)
    return d;
  return max(d, query(ch[x][*c - 'a'], d + 1, c + 1));
}
int n;
string s[N];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    insert(rt, 0, s[i].c_str());
  }
  for (int i = 1; i <= n; i++) {
    cout << query(rt, 0, s[i].c_str()) << '\n';
  }
  return 0;
}

Submission Info

Submission Time
Task E - Karuta
User swiftc
Language C++ (Clang 10.0.0)
Score 500
Code Size 688 Byte
Status AC
Exec Time 171 ms
Memory 68248 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 33
Set Name Test Cases
Sample 00_example_00.txt, 00_example_01.txt
All 00_example_00.txt, 00_example_01.txt, 01_short_00.txt, 01_short_01.txt, 02_max_00.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt, 03_random_13.txt, 03_random_14.txt, 03_random_15.txt, 03_random_16.txt, 03_random_17.txt, 03_random_18.txt, 03_random_19.txt, 03_random_20.txt, 03_random_21.txt, 03_random_22.txt, 03_random_23.txt, 03_random_24.txt, 03_random_25.txt, 03_random_26.txt, 04_hand_00.txt
Case Name Status Exec Time Memory
00_example_00.txt AC 19 ms 15048 KiB
00_example_01.txt AC 13 ms 14928 KiB
01_short_00.txt AC 171 ms 15056 KiB
01_short_01.txt AC 80 ms 28640 KiB
02_max_00.txt AC 67 ms 45716 KiB
03_random_00.txt AC 71 ms 68132 KiB
03_random_01.txt AC 74 ms 68248 KiB
03_random_02.txt AC 72 ms 68216 KiB
03_random_03.txt AC 74 ms 68000 KiB
03_random_04.txt AC 83 ms 59060 KiB
03_random_05.txt AC 84 ms 56404 KiB
03_random_06.txt AC 70 ms 59640 KiB
03_random_07.txt AC 64 ms 55004 KiB
03_random_08.txt AC 38 ms 16160 KiB
03_random_09.txt AC 42 ms 16184 KiB
03_random_10.txt AC 44 ms 15472 KiB
03_random_11.txt AC 61 ms 15140 KiB
03_random_12.txt AC 72 ms 63196 KiB
03_random_13.txt AC 69 ms 59856 KiB
03_random_14.txt AC 69 ms 63544 KiB
03_random_15.txt AC 72 ms 65580 KiB
03_random_16.txt AC 71 ms 63772 KiB
03_random_17.txt AC 80 ms 60832 KiB
03_random_18.txt AC 71 ms 62772 KiB
03_random_19.txt AC 77 ms 61956 KiB
03_random_20.txt AC 80 ms 60084 KiB
03_random_21.txt AC 76 ms 61916 KiB
03_random_22.txt AC 104 ms 34732 KiB
03_random_23.txt AC 114 ms 40456 KiB
03_random_24.txt AC 106 ms 31272 KiB
03_random_25.txt AC 97 ms 36556 KiB
03_random_26.txt AC 107 ms 29240 KiB
04_hand_00.txt AC 87 ms 43320 KiB