제출 #44670

#제출 시각아이디문제언어결과실행 시간메모리
44670choikiwonSelling RNA Strands (JOI16_selling_rna)C++17
0 / 100
1591 ms149452 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int po[100010]; int N, M; string S[100010], P[100010], Q[100010]; vector<int> Len; unordered_map<int, int> Cnt[100010]; vector<int> psum[100010]; int calc(int s, int l, int r) { return (psum[s][r] + mod - (l? 1LL * psum[s][l - 1] * po[r - l + 1] % mod : 0)) % mod; } void getStr(string &s) { while(1) { char c = getchar(); if(c == ' ' || c == '\n') break; s.push_back(c); } } int main() { po[0] = 1; for(int i = 1; i < 100010; i++) { po[i] = 1LL * po[i - 1] * 128 % mod; } scanf("%d %d", &N, &M); getchar(); for(int i = 0; i < N; i++) { getStr(S[i]); } for(int i = 0; i < M; i++) { getStr(P[i]); getStr(Q[i]); } for(int i = 0; i < M; i++) { Len.push_back(P[i].size() + Q[i].size()); } sort(Len.begin(), Len.end()); Len.resize(unique(Len.begin(), Len.end()) - Len.begin()); for(int i = 0; i < N; i++) { psum[i].resize(2 * S[i].size()); for(int j = 0; j < 2 * S[i].size(); j++) { psum[i][j] = S[i][j % (S[i].size())]; if(j) { psum[i][j] += 1LL * psum[i][j - 1] * 128 % mod; psum[i][j] %= mod; } } for(int j = 0; j < Len.size(); j++) { for(int k = 0; k < S[i].size(); k++) { Cnt[ (int)S[i].size() - k ][ calc(i, k, k + Len[j] - 1) ]++; } } } for(int i = 0; i < M; i++) { int hash_val = 0; for(int j = 0; j < Q[i].size(); j++) { hash_val = 1LL * hash_val * 128 % mod; hash_val += Q[i][j]; hash_val %= mod; } for(int j = 0; j < P[i].size(); j++) { hash_val = 1LL * hash_val * 128 % mod; hash_val += P[i][j]; hash_val %= mod; } printf("%d\n", Cnt[ Q[i].size() ][ hash_val ]); } }

컴파일 시 표준 에러 (stderr) 메시지

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:52:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < 2 * S[i].size(); j++) {
                        ~~^~~~~~~~~~~~~~~~~
selling_rna.cpp:60:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < Len.size(); j++) {
                        ~~^~~~~~~~~~~~
selling_rna.cpp:61:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 0; k < S[i].size(); k++) {
                            ~~^~~~~~~~~~~~~
selling_rna.cpp:69:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < Q[i].size(); j++) {
                        ~~^~~~~~~~~~~~~
selling_rna.cpp:74:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < P[i].size(); j++) {
                        ~~^~~~~~~~~~~~~
selling_rna.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...