답안 #547326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547326 2022-04-10T12:04:28 Z Victor 무지개나라 (APIO17_rainbow) C++17
11 / 100
61 ms 3904 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

#include "rainbow.h"

int dr[]={1,-1,0,0};
int dc[]={0,0,1,-1};
int rows,cols,AR,AC,BR,BC;
vector<vector<bool>> grid,vis;

bool valid(int row,int col) { return AR<=row&&row<BR&&AC<=col&&col<BC; }

void dfs(int row,int col) {
    vis[row][col]=1;
    //cout<<"row = "<<row<<" col = "<<col<<" grid = "<<grid[row][col]<<endl;
    rep(k,0,4) {
        int nr=row+dr[k],nc=col+dc[k];
        if(valid(nr,nc)&&!vis[nr][nc]&&!grid[nr][nc]) dfs(nr,nc);
    }
}

void init(int R, int C, int sr, int sc, int M, char *S) {
    rows=R;
    cols=C;
    --sr; --sc;

    rep(i,0,M) {
        if(S[i]=='S') S[i]=0;
        if(S[i]=='N') S[i]=1;
        if(S[i]=='E') S[i]=2;
        if(S[i]=='W') S[i]=3;
    }

    if(rows<=50&&cols<=50) {
        grid.assign(R,vector<bool>(C,0));
        grid[sr][sc]=1;

        rep(i,0,M) {
            sr+=dr[S[i]];
            sc+=dc[S[i]];
            grid[sr][sc]=1;
        }

        //rep(i,0,rows) {
        //    rep(j,0,cols) cout<<grid[i][j]<<' ';
        //    cout<<endl;
        //}
        //cout<<endl;
    }
}

int colour(int ar, int ac, int br, int bc) {
    int ans=0;
    if(rows<=50&&cols<=50) {
        --ar; --ac;
        AR=ar;
        AC=ac;
        BR=br;
        BC=bc;

        vis.assign(rows,vector<bool>(cols,0));
        rep(i,ar,br) { 
            rep(j,ac,bc) {
                if(vis[i][j]||grid[i][j]) continue;
                ++ans;
                dfs(i,j);
            }
        }
    }
    return ans;
}

/*
#include "rainbow.h"

#include <stdio.h>

static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];

int main() {
    scanf("%d %d %d %d", &R, &C, &M, &Q);
    scanf("%d %d", &sr, &sc);
    if (M > 0) {
        scanf(" %s ", S);
    }

    init(R, C, sr, sc, M, S);

    int query;
    for (query = 0; query < Q; query++) {
        int ar, ac, br, bc;
        scanf("%d %d %d %d", &ar, &ac, &br, &bc);
        printf("%d\n", colour(ar, ac, br, bc));
    }

    return 0;
}
*/

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:68:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   68 |             sr+=dr[S[i]];
      |                    ~~~^
rainbow.cpp:69:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   69 |             sc+=dc[S[i]];
      |                    ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 14 ms 324 KB Output is correct
3 Correct 23 ms 476 KB Output is correct
4 Correct 23 ms 340 KB Output is correct
5 Correct 13 ms 392 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 22 ms 440 KB Output is correct
12 Correct 18 ms 412 KB Output is correct
13 Correct 15 ms 400 KB Output is correct
14 Correct 12 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 52 ms 3904 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 14 ms 324 KB Output is correct
3 Correct 23 ms 476 KB Output is correct
4 Correct 23 ms 340 KB Output is correct
5 Correct 13 ms 392 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 22 ms 440 KB Output is correct
12 Correct 18 ms 412 KB Output is correct
13 Correct 15 ms 400 KB Output is correct
14 Correct 12 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Incorrect 61 ms 3856 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 14 ms 324 KB Output is correct
3 Correct 23 ms 476 KB Output is correct
4 Correct 23 ms 340 KB Output is correct
5 Correct 13 ms 392 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 22 ms 440 KB Output is correct
12 Correct 18 ms 412 KB Output is correct
13 Correct 15 ms 400 KB Output is correct
14 Correct 12 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Incorrect 61 ms 3856 KB Output isn't correct
19 Halted 0 ms 0 KB -