提出 #38403507


ソースコード 拡げる

#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
//#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 5e5 + 10;
inline int read()
{
  int s = 0, w = 1;
  char ch = getchar();
  while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int n;
int tot = 1, vis[N], tr[N][26];
string r[N];
inline void insert(string s) //插入字典树
{
  int u = 1;
  for(re int i = 0; i < s.size(); i++){
    int ch = s[i] - 'a';
    if(!tr[u][ch]) tr[u][ch] = ++tot;
    u = tr[u][ch], vis[u] += 1; //记录踏足的次数
  }
}
inline int query(string s)
{
  int u = 1, res = 0;
  for(re int i = 0; i < s.size(); i++){
    int ch = s[i] - 'a'; u = tr[u][ch];
    if(vis[u] > 1) res = i + 1;
  }
  return res;
}
signed main()
{
  n = read();
  for(re int i = 1; i <= n; i++) cin >> r[i], insert(r[i]);
  for(re int i = 1; i <= n; i++) printf("%d\n", query(r[i]));
  return 0;
}

提出情報

提出日時
問題 E - Karuta
ユーザ Booksnow
言語 C++ (GCC 9.2.1)
得点 500
コード長 1234 Byte
結果 AC
実行時間 98 ms
メモリ 72744 KiB

コンパイルエラー

./Main.cpp: In function ‘void insert(std::string)’:
./Main.cpp:29:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |   for(re int i = 0; i < s.size(); i++){
      |              ^
./Main.cpp:29:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   29 |   for(re int i = 0; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
./Main.cpp: In function ‘int query(std::string)’:
./Main.cpp:38:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   38 |   for(re int i = 0; i < s.size(); i++){
      |              ^
./Main.cpp:38:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   38 |   for(re int i = 0; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:47:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   47 |   for(re int i = 1; i <= n; i++) cin >> r[i], insert(r[i]);
      |              ^
./Main.cpp:48:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   48 |   for(re int i = 1; i <= n; i++) printf("%d\n", query(r[i]));
      |              ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 33
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_example_00.txt AC 17 ms 19284 KiB
00_example_01.txt AC 15 ms 19240 KiB
01_short_00.txt AC 98 ms 19144 KiB
01_short_01.txt AC 57 ms 32864 KiB
02_max_00.txt AC 59 ms 46132 KiB
03_random_00.txt AC 79 ms 72744 KiB
03_random_01.txt AC 79 ms 72284 KiB
03_random_02.txt AC 78 ms 72444 KiB
03_random_03.txt AC 80 ms 72200 KiB
03_random_04.txt AC 88 ms 63492 KiB
03_random_05.txt AC 92 ms 60860 KiB
03_random_06.txt AC 70 ms 62872 KiB
03_random_07.txt AC 63 ms 58648 KiB
03_random_08.txt AC 27 ms 20304 KiB
03_random_09.txt AC 32 ms 20468 KiB
03_random_10.txt AC 41 ms 19832 KiB
03_random_11.txt AC 45 ms 19504 KiB
03_random_12.txt AC 72 ms 67192 KiB
03_random_13.txt AC 71 ms 63396 KiB
03_random_14.txt AC 74 ms 67324 KiB
03_random_15.txt AC 77 ms 69368 KiB
03_random_16.txt AC 73 ms 67756 KiB
03_random_17.txt AC 84 ms 65240 KiB
03_random_18.txt AC 77 ms 66992 KiB
03_random_19.txt AC 82 ms 66228 KiB
03_random_20.txt AC 88 ms 64408 KiB
03_random_21.txt AC 80 ms 66320 KiB
03_random_22.txt AC 78 ms 39020 KiB
03_random_23.txt AC 82 ms 44820 KiB
03_random_24.txt AC 77 ms 35548 KiB
03_random_25.txt AC 81 ms 40848 KiB
03_random_26.txt AC 78 ms 33504 KiB
04_hand_00.txt AC 79 ms 47476 KiB