提出 #40401750


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


typedef tree<int,null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update>order_set;
typedef pair<int,int>pr;
#define all(i)     i.begin() , i.end()
#define ft     first
#define sn     second
#define pb push_back


#define en "\n"
#define dbg cout<<"rony\n";

#define MAXN 100010
#define inf -1e6
const ll mod = 1e9+7;

vector<ll>g[MAXN];
int Prime = 31;
int Prime2 = 37;

map<pair<int,int>,int>ma,ma2;

void GetHash(string s)
{
    int p = 1;
    int p2 = 1;

    int HashValue = 0;
    int HashValue2 = 0 ;

    for(int j = 0;j < s.size();j++){
       HashValue = HashValue + (p * s[j]-'a'+1)%mod;
       HashValue %= mod;
       p = p*Prime; p %= mod;
       
       HashValue2 = HashValue2 + (p2 * s[j]-'a'+1)%mod;
       HashValue2 %= mod;
       p2 = p2 * Prime2; p2 %= mod;

       ma2[{HashValue2,j}]++;
       ma[{HashValue,j}]++;   
    }
}
void solve()
{
  int n;
  cin >> n ;
    
    vector<string>v;

   for(int i = 0;i < n ; i++){
    string s;
    cin >> s;
    v.pb(s);
    GetHash(s);

  }

  for(auto i:v)
  {
    string s = i;
    int value = 0; int value2 = 0;
    int p = 1,p2 = 1;
       int an = 0;

    for(int j = 0;j < s.size();j++){
        value = value + (p * s[j]-'a'+1)%mod; value %= mod; p = p * Prime; p %= mod;
        
        value2 = value2 + (p2 * s[j]-'a'+1)%mod; value2 %= mod; p2 = p2 * Prime2; p2 %= mod;

        if(ma[{value,j}] >= 2 && ma2[{value2,j}] >= 2) an = j + 1;
    }

    cout<<an<<en;
  }
}
int main()
{
    IOS;
   int t;
   t = 1;

   // cin >> t;
   int c = 0;
    while ( t-- )
    {
        //cout<<"Case "<<++c<<": ";
        solve();
    }
    return 0;
}   

提出情報

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

コンパイルエラー

./Main.cpp: In function ‘void GetHash(std::string)’:
./Main.cpp:42:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   42 |     for(int j = 0;j < s.size();j++){
      |                   ~~^~~~~~~~~~
./Main.cpp: In function ‘void solve()’:
./Main.cpp:77:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   77 |     for(int j = 0;j < s.size();j++){
      |                   ~~^~~~~~~~~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:95:8: warning: unused variable ‘c’ [-Wunused-variable]
   95 |    int c = 0;
      |        ^

ジャッジ結果

セット名 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 10 ms 5912 KiB
00_example_01.txt AC 7 ms 6040 KiB
01_short_00.txt AC 96 ms 22040 KiB
01_short_01.txt AC 132 ms 25796 KiB
02_max_00.txt AC 763 ms 37612 KiB
03_random_00.txt AC 933 ms 69248 KiB
03_random_01.txt AC 919 ms 69160 KiB
03_random_02.txt AC 872 ms 68764 KiB
03_random_03.txt AC 868 ms 68444 KiB
03_random_04.txt AC 752 ms 58820 KiB
03_random_05.txt AC 734 ms 56196 KiB
03_random_06.txt AC 851 ms 57540 KiB
03_random_07.txt AC 782 ms 52520 KiB
03_random_08.txt AC 67 ms 6868 KiB
03_random_09.txt AC 72 ms 6988 KiB
03_random_10.txt AC 50 ms 7940 KiB
03_random_11.txt AC 53 ms 9676 KiB
03_random_12.txt AC 862 ms 62836 KiB
03_random_13.txt AC 830 ms 58552 KiB
03_random_14.txt AC 991 ms 63112 KiB
03_random_15.txt AC 858 ms 65748 KiB
03_random_16.txt AC 847 ms 63612 KiB
03_random_17.txt AC 885 ms 60272 KiB
03_random_18.txt AC 873 ms 62364 KiB
03_random_19.txt AC 886 ms 61276 KiB
03_random_20.txt AC 883 ms 59452 KiB
03_random_21.txt AC 882 ms 61320 KiB
03_random_22.txt AC 427 ms 34856 KiB
03_random_23.txt AC 508 ms 39236 KiB
03_random_24.txt AC 366 ms 30140 KiB
03_random_25.txt AC 443 ms 38676 KiB
03_random_26.txt AC 344 ms 28356 KiB
04_hand_00.txt AC 500 ms 41760 KiB