답안 #917493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917493 2024-01-28T10:22:14 Z 8pete8 UFO (IZhO14_ufo) C++17
40 / 100
2000 ms 102340 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#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
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
//#define int long long
using namespace std;
const int mod=1e9+7,mxn=1e6+5,Mxn=1e8,inf=1e9,minf=-1e9,lg=30;
int n,m,r,k,p;
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);	
}
struct seg{
    vector<int>v;
    void init(int n){v.resize(2*n+2,minf);}
    void update(int pos,int val,int n){
        pos+=n+1;
        v[pos]=val;
        for(int i=pos;i>0;i>>=1)v[i>>1]=max(v[i],v[i^1]);
    }
    int qry(int l,int r,int n){
        int ans=minf;
        for(l+=n+1,r+=n+1;l<=r;l>>=1,r>>=1){
            if(l&1)ans=max(ans,v[l++]);
            if(!(r&1))ans=max(ans,v[r--]);
        }
        return ans;
    }
}t[2][mxn+10];
int l,mid,ans;
int po,h,bruh;
int32_t main(){
    fastio
    cin>>n>>m>>bruh>>k>>p;
    vector<vector<ll>>grid(n+1,vector<ll>(m+1,0));
    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++){
        t[0][i].init(m);
        for(int j=1;j<=m;j++)t[0][i].update(j,grid[i][j],m);
    }
    for(int j=1;j<=m;j++){
        t[1][j].init(n);
        for(int i=1;i<=n;i++)t[1][j].update(i,grid[i][j],n);
    }
    int d=0,sz=0,cnt,last,x,y;
    bool yes=false;
    while(k--){
        char g;cin>>g;
        cin>>po>>h;
        if(g=='W'||g=='E')d=0,sz=m;
        else d=1,sz=n;
        if(g=='W'||g=='N')yes=true,last=0;
        else yes=false,last=sz+1;
        cnt=bruh;
        while(cnt--){
            if(yes){
                l=last+1,r=sz,mid=0,ans=inf;
                while(l<=r){
                    mid=l+(r-l)/2;
                    if(t[d][po].qry(last+1,mid,sz)>=h)ans=min(ans,mid),r=mid-1;
                    else l=mid+1;
                }
            }
            else{
                l=1,r=last-1,mid=0,ans=minf;
                while(l<=r){
                    mid=l+(r-l)/2;
                    if(t[d][po].qry(mid,last-1,sz)>=h)ans=max(ans,mid),l=mid+1;
                    else r=mid-1;
                }
            }
            last=ans;
            if(last==inf||last==minf)break;
            x=p,y=last;
            if(d)swap(x,y);
            grid[x][y]--;
            t[0][x].update(y,grid[x][y],m);
            t[1][y].update(x,grid[x][y],n);
        }
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)grid[i][j]+=grid[i][j-1];
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)grid[i][j]+=grid[i-1][j];
    ll ans=0;
    for(int i=p;i<=n;i++)for(int j=p;j<=m;j++)ans=max(ans,grid[i][j]-grid[i-p][j]-grid[i][j-p]+grid[i-p][j-p]);
    cout<<ans;
}

Compilation message

ufo.cpp:31:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   31 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
ufo.cpp:36:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   36 | void setIO(string name){
      |                       ^
ufo.cpp:43:20: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   43 |     void init(int n){v.resize(2*n+2,minf);}
      |                    ^
ufo.cpp:44:38: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   44 |     void update(int pos,int val,int n){
      |                                      ^
ufo.cpp:49:30: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   49 |     int qry(int l,int r,int n){
      |                              ^
ufo.cpp:60:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   60 | int32_t main(){
      |              ^
ufo.cpp: In function 'void setIO(std::string)':
ufo.cpp:38:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ufo.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 47192 KB Output is correct
2 Incorrect 14 ms 47196 KB Output isn't correct
3 Incorrect 14 ms 47488 KB Output isn't correct
4 Incorrect 32 ms 47512 KB Output isn't correct
5 Incorrect 84 ms 48472 KB Output isn't correct
6 Incorrect 195 ms 58704 KB Output isn't correct
7 Incorrect 302 ms 73204 KB Output isn't correct
8 Correct 259 ms 73224 KB Output is correct
9 Incorrect 635 ms 72096 KB Output isn't correct
10 Correct 717 ms 73276 KB Output is correct
11 Incorrect 711 ms 72804 KB Output isn't correct
12 Correct 739 ms 73276 KB Output is correct
13 Correct 885 ms 76408 KB Output is correct
14 Correct 648 ms 72800 KB Output is correct
15 Incorrect 1699 ms 73272 KB Output isn't correct
16 Correct 304 ms 72796 KB Output is correct
17 Execution timed out 2057 ms 76312 KB Time limit exceeded
18 Incorrect 290 ms 75604 KB Output isn't correct
19 Incorrect 567 ms 77172 KB Output isn't correct
20 Correct 1221 ms 102340 KB Output is correct