Submission #447379

# Submission time Handle Problem Language Result Execution time Memory
447379 2021-07-26T08:19:27 Z idas Awesome Arrowland Adventure (eJOI19_adventure) C++11
12 / 100
4 ms 332 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=510;

int n, m, g[N][N], ng[N][N];

/*
-1-X
0-N
1-E
2-S
3-W
*/

int c(char x)
{
    if(x=='X') return -1;
    if(x=='N') return 0;
    if(x=='E') return 1;
    if(x=='S') return 2;
    return 3;
}

void re(int p, int &x, int &y)
{
    if(p==0) y--;
    if(p==1) x++;
    if(p==2) y++;
    if(p==3) x--;
}

int main()
{
    setIO();
    cin >> m >> n;
    if(m==3 && n==3){
        FOR(i, 0, m)
        {
            FOR(j, 0, n)
            {
                char x;
                cin >> x;
                g[j][i]=c(x);
            }
        }

        int ans=INF;

        FOR(a, 0, 4) FOR(b, 0, 4) FOR(c, 0, 4) FOR(d, 0, 4) FOR(e, 0, 4) FOR(f, 0, 4) FOR(gi, 0, 4) FOR(h, 0, 4)
        {
            FOR(i, 0, m)
            {
                FOR(j, 0, n)
                {
                    ng[i][j]=0;
                }
            }

            int tot=0;
            if(g[0][0]!=-1){
            ng[0][0]=(g[0][0]+a)%4; tot+=a;}
            if(g[1][0]!=-1){
            ng[1][0]=(g[1][0]+b)%4; tot+=b;}
            if(g[2][0]!=-1){
            ng[2][0]=(g[2][0]+c)%4; tot+=c;}
            if(g[0][1]!=-1){
            ng[0][1]=(g[0][1]+d)%4; tot+=d;}
            if(g[1][1]!=-1){
            ng[1][1]=(g[1][1]+e)%4; tot+=e;}
            if(g[2][1]!=-1){
            ng[2][1]=(g[2][1]+f)%4; tot+=f;}
            if(g[0][2]!=-1){
            ng[0][2]=(g[0][2]+gi)%4; tot+=gi;}
            if(g[1][2]!=-1){
            ng[1][2]=(g[1][2]+h)%4; tot+=h;}

            bool v[n][m];
            FOR(i, 0, n) FOR(j, 0, m) v[i][j]=false;

            int x=0, y=0;
            while(x>=0 && y>=0 && x<n && y<m){
                if(v[x][y]) break;
                if(x==2 && y==2) break;
                v[x][y]=true;
                if(g[x][y]==-1) break;
                re(ng[x][y], x, y);
            }
            if(x==2 && y==2){
                ans=min(ans, tot);
            }
        }

        cout << (ans==INF?-1:ans);
    }
}

Compilation message

adventure.cpp: In function 'void setIO(std::string)':
adventure.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
adventure.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 320 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 4 ms 328 KB Output is correct
4 Correct 4 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -