Submission #1307372

#TimeUsernameProblemLanguageResultExecution timeMemory
1307372gogoim045Patkice (COCI20_patkice)C++20
50 / 50
1 ms584 KiB
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 

void setIO(string name = "") {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (!name.empty()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
 }
}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF (ll)2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define printarr(x) for (ll _do_not_use : x) {cout << _do_not_use << " ";}
#define arrayinp(x) for (size_t i = 0; i < x.size(); i++){cin >> x[i];}

#ifndef ONLINE_JUDGE
#define dbg(x) cout<<#x<<" = "<<x<<ln
#else
#define dbg(x)
#endif
  

void solve(){
    vector<pair<char, p64>> dir = {{'v',{1, 0}}, {'>',{0, 1}}, {'^',{-1, 0}}, {'<',{0, -1}}};
    ll n, m;
    cin >> n >> m;
    vector<string> grid(n+1);
    for (ll i = 1; i <= n; i++)
    {
        cin >> grid[i];
        grid[i]=" "+grid[i];
    }
    p64 start={0, 0}, end={0, 0};
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= m; j++)
        {
            if (grid[i][j]=='o') {start={i, j};}
            else if (grid[i][j]=='x') {end={i, j};}
            if (start.first&&end.first) break;
        }
        if (start.first&&end.first) break;
    }
    char out[4] = {'S', 'E', 'N', 'W'};
    ll out_cnt[4]={INF, INF, INF, INF};
    ll i=0;
    while(i<4)
    {
        ll cost=1;
        p64 cur_i = {start.fi+dir[i].se.fi, start.se+dir[i].se.se};
        while (grid[cur_i.fi][cur_i.se]!='x'&&grid[cur_i.fi][cur_i.se]!='.'&&grid[cur_i.fi][cur_i.se]!='o')
        {
            for (pair<char, p64> d: dir)
            {
                if (grid[cur_i.fi][cur_i.se]==d.first)
                {
                    cur_i.fi+=d.se.fi;
                    cur_i.se+=d.se.se;
                    cost++;
                    break;
                }
            }
        }
        if (grid[cur_i.fi][cur_i.se]=='x') out_cnt[i]=cost;
        i++;
    }

    ll mx_cost=INF-1;
    char mx_char='S';
    for (ll i = 0; i < 4; i++)
    {
        if (mx_cost>out_cnt[i])
        {
            mx_cost=out_cnt[i];
            mx_char=out[i];
        }
        else if (mx_cost==out_cnt[i]&&mx_char>out[i]) mx_char=out[i];
    }
    if (mx_cost==INF-1) cout << ":(";
    else cout << ":)\n" << mx_char;
     
}

int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    for(ll it=1;it<=t;it++) {
        solve();
    }
    return 0;
}

Compilation message (stderr)

patkice.cpp: In function 'void setIO(std::string)':
patkice.cpp:27:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 | freopen((name + ".in").c_str(), "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
patkice.cpp:28:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 | freopen((name + ".out").c_str(), "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...