Submission #1190374

#TimeUsernameProblemLanguageResultExecution timeMemory
1190374TobRaspad (COI17_raspad)C++20
0 / 100
48 ms20292 KiB
#include <bits/stdc++.h>

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const int N = 1e5 + 7, M = 51;

ll n, m;
int mat[N][M];

int main () {
	FIO;
	cin >> n >> m;
	ll res = ((n+1)*(n+2)*(n+3)/6-n-1)*2 - n*(n+1)/2;
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char cc; cin >> cc;
			mat[i][j] = cc-'0';
			if (!mat[i][j]) res += (ll)(i+1)*(n-i);
		}
	}
	
	for (int i = 0; i < n; i++) {
		res -= 2LL*(i+1)*(n-i);
		for (int j = 1; j < m; j++) res -= (!mat[i][j] || !mat[i][j-1])*(ll)(i+1)*(n-i);
	}
	
	res -= (n+1)*n;
	
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < m; j++) res -= (!mat[i][j] || !mat[i-1][j])*(ll)i*(n-i);
	}
	
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < m; j++) {
			res += (!mat[i][j] || !mat[i-1][j] || !mat[i][j-1] || !mat[i-1][j-1])*(ll)i*(n-i);
		}
	}
	
	cout << -res << "\n";

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...