답안 #585352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585352 2022-06-28T17:42:24 Z Ace Selling RNA Strands (JOI16_selling_rna) C++14
10 / 100
1500 ms 117068 KB
#include<bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
typedef pair<pii,pii> piipii;
const int N = 1e5;
const int MULT = 23;

inline int getNum(char x){
	return x-'A';
}

inline pii getHash(string &s, int len){
	int ret = 0;
	for(int i=0;i<len;i++){
		ret *= MULT;
		ret += getNum(s[i]);
	}
	return make_pair(ret, len);
}

unordered_map<int,int> memoDep[N+5];
map<int,int> memoBel[N+5];
string li[N+5];

int n,m;

string pre[N+5], suf[N+5];
set<int> isi[N+5];
vector<int> dep, bel;
map<piipii, int> cnt;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> li[i];
	}
	for(int i=1;i<=m;i++){
		cin >> pre[i] >> suf[i];
		reverse(suf[i].begin(), suf[i].end());
		isi[pre[i].size()].insert(suf[i].size());
		dep.push_back(pre[i].size());
		bel.push_back(suf[i].size());
		cnt[make_pair(getHash(pre[i], pre[i].size()), getHash(suf[i], suf[i].size()))] = 0;
	}
	
	sort(dep.begin(), dep.end());
	sort(bel.begin(), bel.end());
	
	for(int i=1;i<=n;i++){
		int tmp = 0;
		int prev = 0;
		for(auto x: dep){
			if(x > li[i].size()) break;
			for(;prev<x;prev++){
				tmp *= MULT;
				tmp += getNum(li[i][prev]);
			}
			memoDep[i][x] = tmp;
		}
	}
	
	for(int i=1;i<=n;i++){
		int tmp = 0;
		int prev = 0;
		string tmps = li[i];
		reverse(tmps.begin(), tmps.end());
		for(auto x: bel){
			if(x > li[i].size()) break;
			for(;prev<x;prev++){
				tmp *= MULT;
				tmp += getNum(tmps[prev]);
			}
			memoBel[i][x] = tmp;
		}
	}
	
	for(int i=1;i<=n;i++){
		int prev = 0;
		for(auto cand: dep){
			if(cand > li[i].size()) break;
			if(cand == prev) continue;
			prev = cand;
			for(auto cand2: isi[cand]){
				if(cand2 > li[i].size()) break;
//				printf(">>> %d , %d , %d\n", i, cand, cand2);
				piipii tmp = make_pair(make_pair(memoDep[i][cand], cand), make_pair(memoBel[i][cand2], cand2));
				if(cnt.find(tmp) != cnt.end()) cnt[tmp]++;
			}
		}
	}
	
	for(int i=1;i<=m;i++){
		cout << cnt[make_pair(getHash(pre[i], pre[i].size()), getHash(suf[i], suf[i].size()))] << endl;
	}
	
	return 0;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:55:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    if(x > li[i].size()) break;
      |       ~~^~~~~~~~~~~~~~
selling_rna.cpp:70:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |    if(x > li[i].size()) break;
      |       ~~^~~~~~~~~~~~~~
selling_rna.cpp:82:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |    if(cand > li[i].size()) break;
      |       ~~~~~^~~~~~~~~~~~~~
selling_rna.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     if(cand2 > li[i].size()) break;
      |        ~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 13 ms 24532 KB Output is correct
3 Correct 15 ms 24608 KB Output is correct
4 Correct 12 ms 24592 KB Output is correct
5 Correct 13 ms 24540 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 12 ms 24508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 369 ms 76844 KB Output is correct
2 Correct 1221 ms 106552 KB Output is correct
3 Correct 1223 ms 103248 KB Output is correct
4 Execution timed out 1586 ms 117068 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1572 ms 25324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 13 ms 24532 KB Output is correct
3 Correct 15 ms 24608 KB Output is correct
4 Correct 12 ms 24592 KB Output is correct
5 Correct 13 ms 24540 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 12 ms 24508 KB Output is correct
8 Correct 369 ms 76844 KB Output is correct
9 Correct 1221 ms 106552 KB Output is correct
10 Correct 1223 ms 103248 KB Output is correct
11 Execution timed out 1586 ms 117068 KB Time limit exceeded
12 Halted 0 ms 0 KB -