Source Code
#include <iostream>
using namespace std;


int main() {
//     freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	
	char a[100000];
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int x = a[0], y = a[n-1];
	int mn = 100000000;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] == x)
		{
			for (int j = i; j < n; ++j)
			{
				// cout <<a[i] << " " <<  j << " "  << (j-i)+1 << endl;
				if (a[j] == y)
				{
					mn = min(mn, ((j-i)+1));
					// cout << mn << endl;
					break;
				}
			}
		}
	}
	cout << n-mn;
}
Copy
Pop Pop microwave6
GNU G++17
5 ms
404 KB
Accepted
Test Case #1
1 ms
304 KB
Accepted
Input
5
11100
Output
3
Judge Output
3
Checker Message
"3"
Test Case #2
1 ms
376 KB
Accepted
Input
10
1100010011
Output
9
Judge Output
9
Checker Message
"9"
Test Case #3
1 ms
340 KB
Accepted
Input
20
11011111111011100100
Output
18
Judge Output
18
Checker Message
"18"
Test Case #4
1 ms
400 KB
Accepted
Input
30
010100100101001101110000010110
Output
29
Judge Output
29
Checker Message
"29"
Test Case #5
1 ms
324 KB
Accepted
Input
40
1001010010111111111100001010000110100010
Output
38
Judge Output
38
Checker Message
"38"
Test Case #6
1 ms
340 KB
Accepted
Input
100
0110110011011111001110000110010010000111111001100001011101101000001011001101100111011111100111101110
Output
99
Judge Output
99
Checker Message
"99"
Test Case #7
1 ms
336 KB
Accepted
Input
1000
1001100001111111110111000100001010111011011010101101000101011110000011001011010011110101101100011000001010110001101010101111111001010110011101001101110110010101000011101001111100011111110111000000011111101111111011010000110001111111010101000110...
Output
999
Judge Output
999
Checker Message
"999"
Test Case #8
1 ms
372 KB
Accepted
Input
10000
010010101100000100100111010101011100001100101110100011000001000110101101010011000100000010100111010100100011010100101011111100001111101111011110111000010011110010010101111011001011010111000011011011000001001110001111100011100100110111110101000...
Output
9998
Judge Output
9998
Checker Message
"9998"
Test Case #9
5 ms
336 KB
Accepted
Input
100000
10100000100111010011011110000101101110111011111101110001101111011010111111010110000111001111101101010000100010011001010000011011010100000101010001101001000101011010110011000000110010001101010001101000010010100001100011101011010011110110101010...
Output
99999
Judge Output
99999
Checker Message
"99999"
Test Case #10
5 ms
404 KB
Accepted
Input
99999
000101110111100000111110011000010110111100001100110000111111010101101100100100101111010101010100110101001101100110100011101110101011011110100111011011101000110010110100101011000011010010101111010011111110000111101010101100010100100011011101010...
Output
99998
Judge Output
99998
Checker Message
"99998"
Test Case #11
5 ms
324 KB
Accepted
Input
99998
100010111110010111110111000010011111101100110110011110001101110110110001111011111010001010011100101100101011100100100111011111111100001001101010101000101100001110001101000111111111011011001010111110000000000110010011010101110000111011101000110...
Output
99996
Judge Output
99996
Checker Message
"99996"