Submission #472632

# Submission time Handle Problem Language Result Execution time Memory
472632 2021-09-13T23:14:53 Z robell Bob (COCI14_bob) C++17
24 / 120
1000 ms 14920 KB
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define mod 1e9+7
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
int N, M;
int g[1000][1000];
bool v[1000][1000];
int num = 0;
int minx = 1000;
int maxx = -1;
int miny = 1000;
int maxy = -1;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
void dfs(int x, int y, int n){
	if (x<0 || x>=N || y<0 || y>=M) return;
	if (v[x][y]||g[x][y]!=n) return;
	v[x][y]=true; num++;
	minx=min(x,minx);
	maxx=max(x,maxx);
	miny=min(y,miny);
	maxy=max(y,maxy);
	for (int i=0;i<4;i++) dfs(x+dx[i],y+dy[i],n);
}
int main(){
	setIO();
	cin >> N >> M;
	for (int i=0;i<N;i++){
		for (int j=0;j<M;j++){
			cin >> g[i][j];
			v[i][j]=false;
		}
	}
	ll rects = 0;
	for (int i=0;i<N;i++){
		for (int j=i;j<N;j++){
			int prev = 0; int pval = -1;
			for (int k=0;k<M;k++){
				if (pval<0){
					bool w = false;
					for (int z=i;z<=j;z++){
						if (g[i][k]!=g[z][k]){
							w=true;
							break;
						}
					}
					if (!w){
						rects+=(++prev);
						pval=g[i][k];
					}
				}else{
					bool w = false;
					for (int z=i;z<=j;z++){
						if (g[z][k]!=pval){
							w=true;
							break;
						}
					}
					if (!w){
						rects+=(++prev);
					}else{
						k--;
						pval=-1;
						prev=0;
					}
				}
			}
		}
	}
	cout << rects << "\n";
}

Compilation message

bob.cpp: In function 'void setIO(std::string)':
bob.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bob.cpp:20:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 3288 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 3652 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 3916 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 3908 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 11812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 14920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 14656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 14788 KB Time limit exceeded
2 Halted 0 ms 0 KB -