답안 #57122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57122 2018-07-14T04:59:54 Z 윤교준(#1654) Selling RNA Strands (JOI16_selling_rna) C++11
35 / 100
1500 ms 51316 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int __intarr[22000022], *__intarrp = __intarr;
inline int* newint(const unsigned int SZ) {
	__intarrp += SZ;
	return __intarrp - SZ;
}

const int MOD = 1000000009;
const int MOP = 79;
const int MAXN = 100005;
const int MAXM = 100005;

int *AD[MAXN], *AE[MAXN];
int BD[MAXM], CE[MAXM];

int *A[MAXN], An[MAXN];
int *B[MAXM], *C[MAXM], Bn[MAXM], Cn[MAXM];

int N, M;

void parseString(char *S, int *&A, int &L) {
	L = int(strlen(S+1));
	A = newint(L+1);
	for(int i = 1; S[i]; i++) {
		if('A' == S[i]) A[i] = 2;
		else if('C' == S[i]) A[i] = 3;
		else if('G' == S[i]) A[i] = 5;
		else A[i] = 7;
	}
}

void input() {
	char str[100005];

	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) {
		scanf(" %s", str+1);
		parseString(str, A[i], An[i]);
	}
	for(int i = 1; i <= M; i++) {
		scanf(" %s", str+1);
		parseString(str, B[i], Bn[i]);
		scanf(" %s", str+1);
		parseString(str, C[i], Cn[i]);
	}
}

int main() {
	input();

	for(int i = 1; i <= N; i++) {
		AD[i] = newint(An[i]+1);
		for(int j = 1; j <= An[i]; j++) {
			AD[i][j] = (ll(AD[i][j-1]) * MOP + A[i][j]) % MOD;
		}

		AE[i] = newint(An[i]+1);
		for(int j = 1; j <= An[i]; j++)
			AE[i][j] = (ll(AE[i][j-1]) * MOP + A[i][An[i]-j+1]) % MOD;
	}

	for(int i = 1; i <= M; i++) {
		{
			int &ret = BD[i];
			for(int j = 1; j <= Bn[i]; j++)
				ret = (ll(ret) * MOP + B[i][j]) % MOD;
		}
		{
			int &ret = CE[i];
			for(int j = Cn[i]; j; j--)
				ret = (ll(ret) * MOP + C[i][j]) % MOD;
		}
	}

	for(int i = 1; i <= M; i++) {
		int ret = 0;

		for(int j = 1; j <= N; j++) {
			if(An[j] < max(Bn[i], Cn[i])) continue;
			if(AD[j][Bn[i]] != BD[i]) continue;
			if(AE[j][Cn[i]] != CE[i]) continue;
			ret++;
		}

		printf("%d\n", ret);
	}
	
	return 0;
}

Compilation message

selling_rna.cpp: In function 'void input()':
selling_rna.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
selling_rna.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", str+1);
   ~~~~~^~~~~~~~~~~~~~
selling_rna.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", str+1);
   ~~~~~^~~~~~~~~~~~~~
selling_rna.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", str+1);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 3 ms 444 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 3 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 36072 KB Output is correct
2 Correct 416 ms 40340 KB Output is correct
3 Correct 204 ms 43248 KB Output is correct
4 Correct 263 ms 43456 KB Output is correct
5 Correct 263 ms 43456 KB Output is correct
6 Correct 297 ms 43456 KB Output is correct
7 Correct 198 ms 45172 KB Output is correct
8 Correct 327 ms 51316 KB Output is correct
9 Correct 333 ms 51316 KB Output is correct
10 Correct 493 ms 51316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1520 ms 51316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 3 ms 444 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 3 ms 484 KB Output is correct
8 Correct 161 ms 36072 KB Output is correct
9 Correct 416 ms 40340 KB Output is correct
10 Correct 204 ms 43248 KB Output is correct
11 Correct 263 ms 43456 KB Output is correct
12 Correct 263 ms 43456 KB Output is correct
13 Correct 297 ms 43456 KB Output is correct
14 Correct 198 ms 45172 KB Output is correct
15 Correct 327 ms 51316 KB Output is correct
16 Correct 333 ms 51316 KB Output is correct
17 Correct 493 ms 51316 KB Output is correct
18 Execution timed out 1520 ms 51316 KB Time limit exceeded
19 Halted 0 ms 0 KB -