답안 #95788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95788 2019-02-02T15:40:54 Z Bodo171 무지개나라 (APIO17_rainbow) C++14
0 / 100
3000 ms 162724 KB
#include "rainbow.h"
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#define mp make_pair
using namespace std;
const int nmax=200005;
int d1[]={-1,0,1,0};
int d2[]={0,-1,0,1};
map< pair<int,int>,int > rb,norm;
vector<int> ad[8*nmax];
pair<int,int> v[nmax];
int viz[8*nmax];
int n,nr;
void add_rainbow(int l,int c)
{
    if(!rb[mp(l,c)]) v[++n]={l,c};
    rb[mp(l,c)]=1;
}
void add(int l,int c)
{
    int p;
    if((!norm[mp(l,c)])&&(!rb[mp(l,c)]))
        {
            norm[mp(l,c)]=++nr;
            for(int dir=0;dir<4;dir++)
            {
                p=norm[mp(l+d1[dir],c+d2[dir])];
                if(p)
                    ad[p].push_back(nr),ad[nr].push_back(p);
            }
        }
}
void init(int R, int C, int sr, int sc, int M, char *S) {
    add_rainbow(sr,sc);
    for(int i=0;i<M;i++)
    {
        if(S[i]=='N')
            sr--;
        if(S[i]=='S')
            sr++;
        if(S[i]=='W')
           sc--;
        if(S[i]=='E')
          sc++;
        add_rainbow(sr,sc);

    }
}
void dfs(int x)
{
    viz[x]=1;
    for(int i=0;i<ad[x].size();i++)
        if(!viz[ad[x][i]])
          dfs(ad[x][i]);
}
int colour(int ar, int ac, int br, int bc) {
    int cc=0;
    nr=0;
    for(int i=1;i<=n;i++)
        for(int dir=0;dir<4;dir++)
            if(v[i].first+d1[dir]>=ar&&v[i].first+d1[dir]<=br&&v[i].second+d2[dir]>=ac&&v[i].second+d2[dir]<=bc)
          add(v[i].first+d1[dir],v[i].second+d2[dir]);
    for(int i=ar;i<=br;i++)
        add(i,ac),add(i,bc);
    for(int i=ac;i<=bc;i++)
        add(ar,i),add(br,i);
     for(int i=1;i<=nr;i++)
        if(!viz[i])
          dfs(i),cc++;
    norm.clear();
    for(int i=1;i<=nr;i++)
        ad[i].clear(),viz[i]=0;
    return cc;
}

Compilation message

rainbow.cpp: In function 'void dfs(int)':
rainbow.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ad[x].size();i++)
                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 38008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 37880 KB Output is correct
2 Correct 31 ms 37880 KB Output is correct
3 Execution timed out 3044 ms 115832 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 37880 KB Output is correct
2 Correct 1170 ms 162708 KB Output is correct
3 Correct 1211 ms 162724 KB Output is correct
4 Incorrect 1115 ms 130912 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 38008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 38008 KB Output isn't correct
2 Halted 0 ms 0 KB -