Submission #919027

# Submission time Handle Problem Language Result Execution time Memory
919027 2024-01-31T05:22:19 Z TIN Bob (COCI14_bob) C++17
120 / 120
885 ms 13720 KB
#include <bits/stdc++.h>

using namespace std;

#define FNAME "test"

const int N = 1005;

int n,m;
int a[N][N];
int d[N][N];
long long res = 0;

void Task() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(9);
	if (fopen(FNAME".inp","r")) {
		freopen(FNAME".inp","r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

void Solve() {
	//Your Code
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		d[i][m] = m;
		for (int j = m - 1; j > 0; j--) {
			if (a[i][j] == a[i][j + 1]) d[i][j] = d[i][j + 1];
			else d[i][j] = j;
		}
	}
	for (int L = 1; L <= m; L++) {
		for (int R = L; R <= m; R++) {
			int k = 0;
			for (int i = 1; i <= n + 1; i++) {
				if ((d[i][L] >= R) && (i == 1 || a[i][L] == a[i - 1][L])) k++;
				else {
					res += 1LL * k * (k + 1) / 2;
					k = (d[i][L] >= R);
				}
			}
		}
	}
	cout << res << '\n';
}

int main() {
	Task();
	Solve();
	cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
	return 37^37;
}

Compilation message

bob.cpp: In function 'void Task()':
bob.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(FNAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bob.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen(FNAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 7764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 856 ms 12168 KB Output is correct
2 Correct 723 ms 9604 KB Output is correct
3 Correct 677 ms 9552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 884 ms 13704 KB Output is correct
2 Correct 786 ms 9604 KB Output is correct
3 Correct 706 ms 9608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 851 ms 13704 KB Output is correct
2 Correct 701 ms 9600 KB Output is correct
3 Correct 699 ms 9552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 885 ms 13720 KB Output is correct
2 Correct 709 ms 9608 KB Output is correct
3 Correct 685 ms 9592 KB Output is correct