WING

WING ⁡ \operatorname{WING} WING

Topic link: SSL competition 1503 ⁡ \operatorname{SSL competition\ 1503}S S L ratio race . 1 . 5 0 . 3 

topic

Insert picture description here

enter

Insert picture description here

Output

Insert picture description here

Sample input

Insert picture description here
Let you copy:

5 5
1 WINGG
0 WINGG
1 WINGG
0 GGGGG
1 WIGGG

Sample output

-1
1
2

data range

For 40% 40\%. 4 0 % data satisfies:n-<=. 5, C <= 1000; n-<=. 5, C <= 1000;n<=5,c<=1 0 0 0 ;
for100% 100\%. 1 0 0 % data satisfies:n-<= 10; C <. 1 = 0. 6; n-<= 10; C <^ = 10. 6;n<=10;c<=106;

Ideas

This question is a violent question.

We can find that as long as the given sequence is the letter in one position, the letter must be spelled out in this position.
( Md I thought that the two sequences would be disassembled after they were merged, so I couldn’t use it anymore, so I didn’t dare to use this method, gàn! )

Then we count when the letter first appeared in this position. For a sequence to be spelled, if there is a letter in a position and all the sequences are not in this position, it cannot be spelled out. If spelled out, the answer is the maximum time of the first occurrence of the letter in each position of the sequence. (That is, the letter in each position is the latest in that position)

It's gone.

(Remember to use fast reading and fast typing, not 60 60. 6 0 points, plus the Fast Read70707 0 , add100 toboth of them100

Code

#include<cstdio>
#include<iostream> 

using namespace std;

int n, m, x, a[1000001][11], num, fir[5][11], ans, now;
char c, cant;

int read() {
    
    //快读
	int an = 0, zhengfu = 1;
	c = getchar();
	while (c < '0' || c > '9') {
    
    
		if (c == '-') zhengfu = -zhengfu;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
    
    
		an = an * 10 + c - '0';
		c = getchar();
	}
	return an * zhengfu;
}

void writec(int x) {
    
    //快输
	if (x > 9) writec(x / 10);
	putchar(x % 10 + '0');
}

void write(int x) {
    
    
	if (x < 0) {
    
    
		putchar('-');
		writec(-x);
		putchar('\n');
		return ;
	}
	writec(x);
	putchar('\n');
}

int main() {
    
    
	n = read();//读入
	m = read();
	
	for (int i = 1; i <= m; i++) {
    
    
		x = read();//读入
		c = getchar();
		while (c != 'W' && c != 'I' && c != 'N' && c != 'G') c = getchar();
		
		if (!x) {
    
    
			num++;//加入新的串
			for (int j = 1; j <= n; j++) {
    
    
				if (c == 'W') a[num][j] = 1;
					else if (c == 'I') a[num][j] = 2;
						else if (c == 'N') a[num][j] = 3;
							else a[num][j] = 4;
				if (!fir[a[num][j]][j])//这个字母在这个位置第一次出现
					fir[a[num][j]][j] = num;//记录这个字母在这个位置第一次出现的位置
					
				c = getchar();
			}
		}
		else {
    
    //求值
			ans = 0;//初始化
			cant = 0;
			for (int j = 1; j <= n; j++) {
    
    
				if (c == 'W') now = 1;
					else if (c == 'I') now = 2;
						else if (c == 'N') now = 3;
							else now = 4;
				if (!fir[now][j]) {
    
    //这个地方没有出现过这个字母
					cant = 1;
				}
				else ans = max(ans, fir[now][j]);//找到最晚出现的位置
				
				c = getchar();
			}
			if (!cant) write(ans);//输出
				else write(-1);
		}
	}
	
	return 0;
}

postscript

The leader of the topic changed the time to 3 33 seconds, seems to beAAwithout speeding up readingA a.

Guess you like

Origin blog.csdn.net/weixin_43346722/article/details/108123571