Submission #160664

# Submission time Handle Problem Language Result Execution time Memory
160664 2019-10-29T08:09:29 Z mraron Strah (COCI18_strah) C++14
110 / 110
205 ms 74872 KB
/*
ID: noszaly1
TASK: {TASK}
LANG: C++11               
*/

//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}
#define int ll
string t[2002];
int d[2002][2002];
int ans[2002][2002];
main() {
	IO;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;++i) {
		string akt;
		cin>>akt;
		t[i]="#";
		t[i]+=akt;
		t[i]+="#";
	}
	

	
	for(int i=0;i<n;++i) {
		for(int j=0;j<=m+1;++j) {
			if(i==0) {
				if(t[i][j]=='.') d[i][j]=1;
			}else {
				if(t[i][j]=='#') d[i][j]=0;
				else d[i][j]=d[i-1][j]+1;
			}
		}
	}
	
		
	/*for(int i=0;i<n;++i) {
		for(int j=0;j<=m+1;++j) {
			cerr<<d[i][j]<<" ";
		}cerr<<"\n";
	}*/
	
	for(int i=0;i<n;++i) {
		vector<pair<int,int>> s;
		for(int j=0;j<=m+1;++j) {
			#define h xx
			#define w yy
			int w=0;
			while(s.size()>1 && s.back().h>=d[i][j]) {
				int h=max(s[s.size()-2].h, d[i][j]);
				w+=s.back().w;
				ans[h+1][w]++;
				ans[s.back().h+1][w]--;
				s.pop_back();
			}
			
			s.push_back({d[i][j],w+1});
			//for(auto i:s) cerr<<i.xx<<":"<<i.yy<<"; ";
			//cerr<<"\n";
		}
	}
	
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=m;++j) {
			ans[i+1][j]+=ans[i][j];
		}
		int a=0,b=0;
		for(int j=m;j>=1;j--) {
			a+=ans[i][j];
			b+=a;
			ans[i][j]=b;
		}
	}
	
	int osszans=0;
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=m;++j) {
			osszans+=ans[i][j]*i*j;
		}
	}
	
	cout<<osszans<<"\n";
	return 0;
}

Compilation message

strah.cpp:64:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4448 KB Output is correct
2 Correct 8 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4576 KB Output is correct
2 Correct 9 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4472 KB Output is correct
2 Correct 8 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 26616 KB Output is correct
2 Correct 129 ms 55032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 49280 KB Output is correct
2 Correct 192 ms 71904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 31748 KB Output is correct
2 Correct 139 ms 58588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 20032 KB Output is correct
2 Correct 150 ms 67948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 74832 KB Output is correct
2 Correct 205 ms 74872 KB Output is correct