Submission #909857

# Submission time Handle Problem Language Result Execution time Memory
909857 2024-01-17T13:41:01 Z 8pete8 Nafta (COI15_nafta) C++17
34 / 100
1000 ms 46200 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<float.h>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,ll>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
using namespace std;
#define int long long
#define double long double
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
const int mod=1e9+7,mxn=3e5,lg=30,inf=1e18,minf=-1e9,Mxn=100000;
int n,m;
char grid[2002][2002];
int dp[2002][2002],val[2002],cost[2002][2002],on[2002];
bool vis[2002][2002];
int u[4]={0,0,1,-1},r[4]={1,-1,0,0};
int ans=0,sum=0;
void dfs(int cx,int cy){
    on[cy]=1;
    sum+=(grid[cx][cy]-'0');
    vis[cx][cy]=true;
    for(int i=0;i<4;i++){
        int nx=cx+u[i],ny=cy+r[i];
        if(nx<0||ny<0||nx>=n||ny>=m)continue;
        if(vis[nx][ny]||grid[nx][ny]=='.')continue;
        dfs(nx,ny);
    }
}
int32_t main(){
    fastio
    int sub=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>grid[i][j];
    for(int i=0;i<n;i++)for(int j=0;j<m;j++){
        if(vis[i][j]||grid[i][j]=='.')continue;
        sum=0;
        dfs(i,j);
        for(int k=0;k<m;k++)if(on[k]){
            val[k]+=sum;
            for(int l=0;l<k;l++)if(on[l])cost[l][k]+=sum;
        }
        for(int k=0;k<m;k++)on[k]=0;
    }
    for(int i=1;i<=m;i++){
        for(int j=0;j<m;j++){
            dp[j][i]=val[j];
            if(j)dp[j][i]=max(dp[j][i],dp[j-1][i]);
            for(int l=0;l<j;l++)dp[j][i]=max(dp[j][i],dp[l][i-1]-cost[l][j]+val[j]);
        }
    }
    for(int i=1;i<=m;i++)cout<<dp[m-1][i]<<'\n';
}

Compilation message

nafta.cpp: In function 'int32_t main()':
nafta.cpp:57:9: warning: unused variable 'sub' [-Wunused-variable]
   57 |     int sub=0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 27 ms 17500 KB Output is correct
8 Correct 22 ms 17540 KB Output is correct
9 Correct 26 ms 18524 KB Output is correct
10 Correct 27 ms 17500 KB Output is correct
11 Correct 20 ms 17752 KB Output is correct
12 Correct 21 ms 17372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 27 ms 17500 KB Output is correct
8 Correct 22 ms 17540 KB Output is correct
9 Correct 26 ms 18524 KB Output is correct
10 Correct 27 ms 17500 KB Output is correct
11 Correct 20 ms 17752 KB Output is correct
12 Correct 21 ms 17372 KB Output is correct
13 Execution timed out 1031 ms 46200 KB Time limit exceeded
14 Halted 0 ms 0 KB -