Submission #865859

# Submission time Handle Problem Language Result Execution time Memory
865859 2023-10-25T00:49:26 Z weakweakweak Patkice (COCI20_patkice) C++14
30 / 50
1 ms 1236 KB
//簽到題
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fs first
#define sc second

int n, m, dx[4]={0,0,1,-1}, dy[4]={1,-1,0,0};
pii st, ed;
string s[110];

int fa[210000]={0};

int f(int x, int y){return x*m+y+100000;}
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void uni(int x, int y){
    x=find(x),y=find(y);
    if(x!=y)fa[x]=y;
}

void finish(string s){
    cout << ":)\n" << s << '\n';
    exit(0);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i=0; i<210000; i++)fa[i]=i;
    for(int i=0; i<n; i++){
        cin >>s[i];
        for(int j=0; j<m; j++){
            if(s[i][j]=='x')ed={i,j};
            else if(s[i][j]=='o')st={i,j};
            else if(s[i][j]=='>')uni(f(i,j),f(i,j+1));
            else if(s[i][j]=='<')uni(f(i,j),f(i,j-1));
            else if(s[i][j]=='v')uni(f(i,j),f(i+1,j));
            else if(s[i][j]=='^')uni(f(i,j),f(i-1,j));
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            int x=find(f(i,j));
            x-=100000;
        }
    }
    if(find(f(st.fs+1,st.sc))==find(f(ed.fs,ed.sc)))finish("S");
    if(find(f(st.fs-1,st.sc))==find(f(ed.fs,ed.sc)))finish("N");
    if(find(f(st.fs,st.sc+1))==find(f(ed.fs,ed.sc)))finish("E");
    if(find(f(st.fs,st.sc-1))==find(f(ed.fs,ed.sc)))finish("W");
    cout << ":(\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1192 KB Output isn't correct
2 Halted 0 ms 0 KB -