답안 #31234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31234 2017-08-14T16:24:33 Z gs14004 Repeating Subsequence Tests (KRIII5_RST) C++14
0 / 7
16 ms 631916 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef long long lint;
const int MAXN = 1000005;
const int E = 52;
const int mod = 1e9 + 7;

int code(char x){
	if(x >= 'A' && x <= 'Z') return x - 'A';
	return x - 'a' + 26;
}

int n, q;
char str[MAXN];
int sum[MAXN][53];
int del[MAXN][53];
int sui[MAXN][53];
int arr[53][53];

void init(){
	for(int i=1; i<=n; i++){
		str[i] = code(str[i]);
	}
	for(int i=0; i<=E; i++){
		arr[i][i] = sum[0][i] = 1;
	}
	for(int i=1; i<=n; i++){
		for(int j=0; j<=E; j++){
			sum[i][j] = (2ll * sum[i-1][j] % mod - arr[str[i]][j] + mod) % mod;
			arr[str[i]][j] = sum[i][j];
		}
	}
	memset(arr, 0, sizeof(arr));
	for(int i=0; i<=E; i++){
		arr[i][i] = sui[0][i] = 1;
	}
	for(int i=1; i<=n; i++){
		for(int j=0; j<=E; j++){
			sui[i][j] = (1ll * sui[i-1][j] - arr[str[i]][j] + del[i-1][j] + mod) % mod;
			del[i][j] = arr[str[i]][j];
			arr[str[i]][j] = (2ll * arr[str[i]][j] - del[i-1][j] + mod) % mod;
		}
		for(int j=0; j<=E; j++){
			sui[i][j] = (1ll * sui[i][j] + arr[str[i]][j] - del[i][j] + mod) % mod;
		}
	}
}

int query(int s, int e){
	lint ret = 0;
	for(int i=0; i<E; i++){
		ret += 1ll * sum[e][i] * (mod - del[s-1][i]) % mod;
	}
	ret += 1ll * sum[e][E] * (mod + 1 - del[s-1][E]) % mod;
	ret %= mod;
	return ret;
}

int a[MAXN], b[MAXN];

int main(){
	scanf("%s %d",str + 1,&q);
	n = strlen(str + 1);
	if(n > 100000 || q > 100000){
		puts("august14");
		return 0;
	}
	int c0, c1, c2;
	scanf("%d %d %d %d %d",&a[0],&b[0],&c0,&c1,&c2);
	for(int i=1; i<q; i++){
		a[i] = (1ll * a[i-1] * c0 + 1ll * b[i-1] * c1 + c2) % mod;
		b[i] = (1ll * b[i-1] * c0 + 1ll * a[i-1] * c1 + c2) % mod;
	}
	init();
	int ans = 0;
	for(int i=0; i<q; i++){
		a[i] %= n;
		b[i] %= n;
		if(a[i] > b[i]) swap(a[i], b[i]);
		ans ^= query(a[i] + 1, b[i] + 1);
	}
	cout << ans;
}

Compilation message

RST.cpp: In function 'void init()':
RST.cpp:30:53: warning: array subscript has type 'char' [-Wchar-subscripts]
    sum[i][j] = (2ll * sum[i-1][j] % mod - arr[str[i]][j] + mod) % mod;
                                                     ^
RST.cpp:31:14: warning: array subscript has type 'char' [-Wchar-subscripts]
    arr[str[i]][j] = sum[i][j];
              ^
RST.cpp:40:47: warning: array subscript has type 'char' [-Wchar-subscripts]
    sui[i][j] = (1ll * sui[i-1][j] - arr[str[i]][j] + del[i-1][j] + mod) % mod;
                                               ^
RST.cpp:41:26: warning: array subscript has type 'char' [-Wchar-subscripts]
    del[i][j] = arr[str[i]][j];
                          ^
RST.cpp:42:14: warning: array subscript has type 'char' [-Wchar-subscripts]
    arr[str[i]][j] = (2ll * arr[str[i]][j] - del[i-1][j] + mod) % mod;
              ^
RST.cpp:42:38: warning: array subscript has type 'char' [-Wchar-subscripts]
    arr[str[i]][j] = (2ll * arr[str[i]][j] - del[i-1][j] + mod) % mod;
                                      ^
RST.cpp:45:45: warning: array subscript has type 'char' [-Wchar-subscripts]
    sui[i][j] = (1ll * sui[i][j] + arr[str[i]][j] - del[i][j] + mod) % mod;
                                             ^
RST.cpp: In function 'int main()':
RST.cpp:63:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s %d",str + 1,&q);
                           ^
RST.cpp:70:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d %d",&a[0],&b[0],&c0,&c1,&c2);
                                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 631916 KB Output is correct
2 Incorrect 16 ms 631916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 631916 KB Output is correct
2 Incorrect 16 ms 631916 KB Output isn't correct
3 Halted 0 ms 0 KB -