QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#884942#9922. Mah-jongAugenstern_WA 917ms5968kbC++141.1kb2025-02-06 12:00:102025-02-06 12:00:14

Judging History

This is the latest submission verdict.

  • [2025-02-06 12:00:14]
  • Judged
  • Verdict: WA
  • Time: 917ms
  • Memory: 5968kb
  • [2025-02-06 12:00:10]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 5e5 + 10;
int n , ans;
int a[N] , num[11] , X[N];
void solve() {
	int sum = 0; ans = 0;
	for(int i = 1;i <= n;i ++) {
		int sum = 0;
		for(int j = 1;j <= 8;j ++) num[j] = 0;
		for(int j = i;j <= n;j ++) {
			num[a[j]] ++; sum ++; sum -= 3;
			if(num[a[j]] == 3) num[a[j]] = 0;
			else if(num[a[j] - 1] && num[a[j]] && num[a[j] + 1]) {
				num[a[j] - 1] --; num[a[j]] --; num[a[j] + 1] --;
			}
			else if(a[j] - 2 >= 1 && num[a[j] - 1] && num[a[j]] && num[a[j] - 2]) {
				num[a[j] - 1] --; num[a[j]] --; num[a[j] + 1] --;
			}
			else if(a[j] + 2 <= 8 && num[a[j] + 1] && num[a[j]] && num[a[j] + 2]) {
				num[a[j] + 1] --; num[a[j]] --; num[a[j] + 2] --;
			}
			else sum += 3;
			if(!sum) ans ++;
		}
	}
	printf("%lld\n",ans);
}

signed main() {
	int t; cin >> t;
	while(t --) {
		scanf("%lld",&n);
		for(int i = 1;i <= n;i ++) {
			scanf("%lld",&a[i]);
		}
		solve();
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
/*
5 4 1 1 1 1 6 1 2 3 1 2 3 7 6 5 8 7 6 3 2 8 1 2 1 2 1 2 1 3 9 2 2 4 4 1 1 1 3 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5968kb

input:

5
4
1 1 1 1
6
1 2 3 1 2 3
7
6 5 8 7 6 3 2
8
1 2 1 2 1 2 1 3
9
2 2 4 4 1 1 1 3 3

output:

2
5
1
3
2

result:

ok 5 number(s): "2 5 1 3 2"

Test #2:

score: -100
Wrong Answer
time: 917ms
memory: 5964kb

input:

100
992
8 1 8 1 2 3 6 6 1 3 1 8 7 7 4 7 7 1 6 6 4 8 3 7 3 5 1 4 4 7 5 7 5 7 4 3 7 5 2 8 7 1 6 3 6 2 4 3 2 3 1 6 3 1 3 2 6 6 7 4 6 1 1 4 6 4 7 7 8 5 6 4 1 5 4 8 2 4 4 2 1 3 5 7 6 8 3 7 6 6 5 6 4 2 5 4 3 7 3 5 5 3 3 2 7 8 2 7 2 4 4 3 4 1 1 3 5 5 4 6 3 3 3 2 6 1 2 6 4 8 8 6 6 8 7 3 1 1 8 8 7 2 5 6 3 5 ...

output:

10315
10710
2917
1651
26197
4039
5070
11587
37291
57643
5801
19838
30753
54180
21294
947
14848
18454
13948
1
12844
0
10609
6297
15712
2
14602
20019
8
37111
12875
22933
8442
12864
7480
5688
1217
2464
11698
51430
22206
6058
443
12649
63958
1388
6268
20724
4104
7225
7797
4215
26761
244
307
5974
17453
9...

result:

wrong answer 1st numbers differ - expected: '51699', found: '10315'