답안 #1005488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005488 2024-06-22T13:45:26 Z De3b0o 바이러스 (JOI19_virus) C++14
6 / 100
2000 ms 22436 KB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)
 
using namespace std;
 
ll n, m, d;
string s;
ll g[809][809];
bool vis[809][809];
bool vs[809][809];
ll fans[809][809];
ll t[2][2][2][2];
ll mn, ans;
ll cost;
ll timer;
 
void bfs(ll d1, ll d2, ll o)
{
    queue<pll> q;
    q.push({d1,d2});
    vector<pll> v;
    while(!q.empty())
    {
        auto it = q.front();
        q.pop();
        ll x = it.F, y = it.S;
        if(vis[x][y]||x==0||y==0||x>n||y>m)
            continue;
        vis[x][y]=1;
        v.pb({x,y});
        if(vs[x][y])
        {
            cost=1e18;
            break;
        }
        cost++;
        for(int h = 0 ; 4>h ; h++)
        {
            ll i = x , j = y;
            if(h==1)
                i--;
            else if(h==2)
                i++;
            else if(h)
                j--;
            else
                j++;
            bool l1 , l2 , l3 , l4;
            l1 = l2 = l3 = l4 = 0;
            l1=(i<n&&vis[i+1][j]);
            l2=(i>1&&vis[i-1][j]);
            l3=(j<m&&vis[i][j+1]);
            l4=(j>1&&vis[i][j-1]);
            if(t[l1][l2][l3][l4]>=g[i][j])
                q.push({i,j});
        }
    }
    for(auto it : v)
        vis[it.F][it.S]=0;
    vs[d1][d2]=1;
    fans[d1][d2]=cost;
}
 
int main()
{
    cin >> d >> n >> m;
    cin >> s;
    for(int i = 1 ; n>=i ; i++)
    {
        for(int j = 1 ; m>=j ; j++)
        {
            cin >> g[i][j];
            if(g[i][j]==0)
                g[i][j]=100001;
        }
    }
    s+=s;
    d+=d;
    for(int h = 0 ; 16>h ; h++)
    {
        ll mx = 0;
        ll c = 0;
        bool l1, l2, l3, l4;
        l1 = l2 = l3 = l4 = 0;
        l1=((1<<0)&h);
        l2=((1<<1)&h);
        l3=((1<<2)&h);
        l4=((1<<3)&h);
        for(int i = 0 ; d>i ; i++)
        {
            if((s[i]=='S'&&l1)||(s[i]=='N'&&l2)||(s[i]=='E'&&l3)||(s[i]=='W'&&l4))
            {
                c++;
                mx=max(mx,c);
            }
            else
                c=0;
        }
        if(mx==d)
            mx=100000;
        t[l1][l2][l3][l4]=mx;
    }
    vector<pll> idx;
    for(int i = 1 ; n>=i ; i++)
        for(int j = 1 ; m>=j ; j++)
            idx.pb({i,j});
    mn=1e18;
    timer=1;
    for(int h = 0 ; idx.size()>h ; h++)
    {
        ll i = idx[h].F;
        ll j = idx[h].S;
        if(g[i][j]==100001)
            continue;
        cost=0;
        ll o = -1;
        if(vis[i][j])
            o=vis[i][j];
        bfs(i,j,o);
        if(mn>cost)
        {
            ans=0;
            mn=cost;
        }
        if(mn==cost)
            ans++;
        timer++;
    }
    cout << mn << "\n" << ans*mn;
}

Compilation message

virus.cpp: In function 'int main()':
virus.cpp:124:31: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  124 |     for(int h = 0 ; idx.size()>h ; h++)
      |                     ~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2652 KB Output is correct
2 Correct 144 ms 22436 KB Output is correct
3 Execution timed out 2033 ms 22284 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 8 ms 2908 KB Output is correct
3 Correct 23 ms 2848 KB Output is correct
4 Correct 8 ms 2908 KB Output is correct
5 Correct 23 ms 2908 KB Output is correct
6 Correct 24 ms 5016 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 24 ms 4864 KB Output is correct
9 Correct 2 ms 4696 KB Output is correct
10 Correct 4 ms 2908 KB Output is correct
11 Correct 1 ms 4688 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 27 ms 5116 KB Output is correct
14 Correct 25 ms 5108 KB Output is correct
15 Correct 28 ms 5120 KB Output is correct
16 Correct 21 ms 4860 KB Output is correct
17 Correct 12 ms 4956 KB Output is correct
18 Correct 3 ms 4700 KB Output is correct
19 Correct 23 ms 4892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2652 KB Output is correct
2 Correct 144 ms 22436 KB Output is correct
3 Execution timed out 2033 ms 22284 KB Time limit exceeded
4 Halted 0 ms 0 KB -