Submission #920825

# Submission time Handle Problem Language Result Execution time Memory
920825 2024-02-03T04:46:33 Z 8pete8 Raspad (COI17_raspad) C++17
0 / 100
6000 ms 147392 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#define int long long
const int mod=1e9+7,mxn=1e5+5,lg=30,inf=1e18,minf=-1e9,Mxn=100000;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}
char grid[mxn+5][55];
int col[mxn+5][55];
int u[4]={1,-1,0,0},r[4]={0,0,1,-1},nx,ny,cx,cy;
int n,m,cnt=0;
int stp[mxn+10];
void bfs(int x,int y){
	queue<pii>q;
	q.push({x,y});
	cnt++;
	stp[cnt]=x;
	col[x][y]=cnt;
	while(!q.empty()){
		cx=q.front().f,cy=q.front().s;
		q.pop();
		for(int i=0;i<4;i++){
			nx=cx+u[i],ny=cy+r[i];
			if(nx<=0||nx>n||ny<=0||ny>m)continue;
			if(col[nx][ny]||grid[nx][ny]=='0')continue;
			q.push({nx,ny});
			col[nx][ny]=cnt;
		}
	}
}
int am[mxn+5][55];
int32_t main(){
	fastio
	cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>grid[i][j];	
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(grid[i][j]=='1'&&col[i][j]==0)bfs(i,j);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(col[i][j]!=col[i][j-1])am[i][col[i][j]]++;
	int ans=0;
	stack<pii>st[cnt+1];
	vector<pii>keep;
	//3+1
	for(int j=1;j<=cnt;j++)st[j].push({-1,0});
	for(int i=1;i<=n;i++){
		for(int j=1;j<=cnt;j++){
			if(am[i][j]){
				while(!st[j].empty()&&st[j].top().f>=am[i][j])st[j].pop();
				st[j].push({am[i][j],i});
			}
			keep.clear();
			while(!st[j].empty())keep.pb(st[j].top()),st[j].pop();
			reverse(all(keep));
			for(int k=1;k<keep.size();k++)ans+=(keep[k].f*(keep[k].s-keep[k-1].s));
			for(auto i:keep)st[j].push(i);
		}
	}
	cout<<ans;
	return 0;
}

Compilation message

raspad.cpp: In function 'int32_t main()':
raspad.cpp:82:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |    for(int k=1;k<keep.size();k++)ans+=(keep[k].f*(keep[k].s-keep[k-1].s));
      |                ~^~~~~~~~~~~~
raspad.cpp: In function 'void setIO(std::string)':
raspad.cpp:35:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raspad.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 52144 KB Output is correct
2 Execution timed out 6071 ms 147392 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -