답안 #495632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495632 2021-12-19T16:05:25 Z ktkerem Patkice (COCI20_patkice) C++17
30 / 50
1 ms 332 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define debu cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e13 + 7; 
const ll ous=1e6 + 5;
const ll dx[4] = {1 , -1 , 0 , 0} , dy[4] = {0,0,-1,1};
string h[105];ll n , m;
ll fun(llll x){
    vector<vector<ll>> vis(105 , vector<ll>(105 , 0));
    ll o = 0 , kd = 0;
    while(x.fi >-1 && x.fi < n && x.sec > -1 && x.sec < m && h[x.fi][x.sec] != '.' && h[x.fi][x.sec] != 'o' && vis[x.fi][x.sec] == 0){
        vis[x.fi][x.sec] = 1;
        o++;
        if(h[x.fi][x.sec] == 'x'){
            kd = 1;
            break;
        }
        if(h[x.fi][x.sec] == 'v'){
            x.fi++;
        }
        else if(h[x.fi][x.sec] == '>'){
            x.sec++;
        }
        else if(h[x.fi][x.sec] == '<'){
            x.sec--;
        } 
        else if(h[x.fi][x.sec] == '^'){
            x.fi--;
        }
    }
    return (kd==1 ?o :limit);
}
void solve(){
    cin >> n >> m;
    fora(i,n){
        cin >> h[i];
    }
    llll loc;
    fora(i,n){
        fora(j,m){
            if(h[i][j] == 'o'){
                loc = {i , j};
                break;
            }
        }
    }
    llll mx = {limit , limit};
    fora(i,4){
        ll z =fun({loc.fi + dx[i] , loc.sec + dy[i]});
        //cout << z << "\n";
        if(z < mx.fi){
            mx.fi = z;mx.sec = i+1;
        }
    }
    if(mx.fi == limit){
        cout << ":(\n";
        return;
    }
    cout << ":)\n";
    if(mx.sec == 1){
        cout << "S\n";
    }
    else if(mx.sec == 2){
        cout << "N\n";
    }
    else if(mx.sec == 3){
        cout << "W\n";
    }
    else if(mx.sec == 4){
        cout << "E\n";
    }
    return;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Halted 0 ms 0 KB -