답안 #320737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320737 2020-11-09T16:23:22 Z parsabahrami Selling RNA Strands (JOI16_selling_rna) C++17
35 / 100
191 ms 132964 KB
//! The Leader Of Retards Bemola
#include <bits/stdc++.h>
 
using namespace std;

typedef int ll;
typedef pair<ll, ll> pll;
 
#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
    	if (b & 1) ans = ans * a % md;
    return ans;
}
const ll MAXN = 3e5 + 10;
const ll MOD  = 1e9 + 7;
ll nxt[2][MAXN][30], L[MAXN], R[MAXN], n, q, id[2] = {1, 1};
vector<ll> vec[MAXN]; string C[MAXN];

void update1(string x, ll p) {
	ll v = 0;
	for (ll i = 0; i < sz(x); i++) {
		if (nxt[0][v][x[i] - 'A'] == 0) nxt[0][v][x[i] - 'A'] = id[0]++;
		L[v] = min(L[v], p);
		R[v] = max(R[v], p);
		v = nxt[0][v][x[i] - 'A'];
	}
	L[v] = min(L[v], p);
	R[v] = max(R[v], p);
}

void update2(string x, ll p) {
	ll v = 0;
	for (ll i = sz(x) - 1; ~i; i--) {
		if (nxt[1][v][x[i] - 'A'] == 0) nxt[1][v][x[i] - 'A'] = id[1]++;
		vec[v].push_back(p);
		v = nxt[1][v][x[i] - 'A'];
	}
	vec[v].push_back(p);
}

pll get1(string x) {
	ll v = 0;
	for (ll i = 0; i < sz(x); i++) {
		if (nxt[0][v][x[i] - 'A'] == 0) return {-1, -1};
		v = nxt[0][v][x[i] - 'A'];
	}
	return {L[v], R[v]};
}

ll get2(string x, ll l, ll r) {
	if (r == -1 || l == -1) return 0;
	ll v = 0;
	for (ll i = sz(x) - 1; ~i; i--) {
		if (nxt[1][v][x[i] - 'A'] == 0) return 15;
		v = nxt[1][v][x[i] - 'A'];
	}
	return upper_bound(all(vec[v]), r) - lower_bound(all(vec[v]), l);
}

int main() {
	fill(L, L + MAXN, MOD);
	scanf("%d%d", &n, &q);
	for (ll i = 1; i <= n; i++) {
		cin >> C[i];
	}
	sort(C + 1, C + n + 1);
	for (ll i = 1; i <= n; i++) {
		update1(C[i], i);
		update2(C[i], i);
	}
	while (q--) {
		string s, t;
		cin >> s >> t;
		pll X = get1(s);
		printf("%d\n", get2(t, X.F, X.S));
	}
    return 0;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 18028 KB Output is correct
2 Correct 13 ms 18028 KB Output is correct
3 Correct 12 ms 18028 KB Output is correct
4 Correct 13 ms 18028 KB Output is correct
5 Correct 12 ms 18028 KB Output is correct
6 Correct 14 ms 18028 KB Output is correct
7 Correct 13 ms 18028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 191 ms 132964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 19168 KB Output is correct
2 Correct 120 ms 19556 KB Output is correct
3 Correct 146 ms 19168 KB Output is correct
4 Correct 123 ms 18788 KB Output is correct
5 Correct 126 ms 19432 KB Output is correct
6 Correct 156 ms 19168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 18028 KB Output is correct
2 Correct 13 ms 18028 KB Output is correct
3 Correct 12 ms 18028 KB Output is correct
4 Correct 13 ms 18028 KB Output is correct
5 Correct 12 ms 18028 KB Output is correct
6 Correct 14 ms 18028 KB Output is correct
7 Correct 13 ms 18028 KB Output is correct
8 Runtime error 191 ms 132964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -