답안 #1031884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031884 2024-07-23T08:25:28 Z vjudge1 화성 (APIO22_mars) C++17
29 / 100
85 ms 4612 KB
#include "mars.h"
#include<bits/stdc++.h>
using namespace std;
bitset<50> grid[50];
void flod(int i,int j){
    if(i<0||i>30||j<0||j>30)return;
    if(!grid[i][j]) return;
    grid[i][j]=0;
    flod(i-1,j);
    flod(i+1,j);
    flod(i,j+1);
    flod(i,j-1);
}
string howmanyislands(int n){
    int ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            ans+=grid[i][j],flod(i,j);
    string str;
    for(int i=0;i<100;i++)
        str+=48+(ans&1),ans>>=1;
    return str;
}
string encode_grid(int i,int j){
    string str;
    for(int I=0;I<10;I++)
        for(int J=0;J<10;J++)
            str+=48+grid[i+I][j+J];
    return str;
}
void putintogrid(string a,int i,int j){
    int CC=0;
    for(int I=0;I<10;I++) for(int J=0;J<10;J++)
        grid[i+I][j+J]=grid[i+I][j+J]|a[CC++]=='1';
}
std::string process(std::vector <std::vector<std::string>> a, int i, int j, int k, int n) {
    for(int i=0;i<2*n+1;i++)
        grid[i].reset();
    if(n<=4) {
        for(int i=0;i<2*n+1;i++)
            grid[i].reset();
        if(i&1||j&1) return a[0][0];
        if(max(i,j)==2*n-2*k-2) {
            grid[i][j]=a[0][0][0]=='1';
            grid[i+1][j]=a[1][0][0]=='1';
            grid[i][j+1]=a[0][1][0]=='1';
            grid[i+1][j+1]=a[1][1][0]=='1';
            grid[i+2][j+1]=a[2][1][0]=='1';
            grid[i+1][j+2]=a[1][2][0]=='1';
            putintogrid(a[2][0],i+2,j);
            putintogrid(a[2][2],i+2,j+2);
            putintogrid(a[0][2],i,j+2);
        } else return a[0][0];
        if(k==n-1)
            return howmanyislands(2*n+1);
        return encode_grid(i,j);
    }
    int szofg=2*n;
    set<int> important;
    important.insert(0);
    important.insert(szofg);
    important.insert(szofg-10);
    set<int>important2;
    important2.insert(0);
    important2.insert(szofg-10);
    if(szofg>20)
        important2.insert(szofg-20);
    if(szofg>20)
        important.insert(szofg-20);
    if(k==n-1){
        int k=2*n-9;
        if(n==5) {
            grid[i][j]=a[0][0][0]=='1';
            grid[i+1][j]=a[1][0][0]=='1';
            grid[i][j+1]=a[0][1][0]=='1';
            grid[i+1][j+1]=a[1][1][0]=='1';
            grid[i+2][j+1]=a[2][1][0]=='1';
            grid[i+1][j+2]=a[1][2][0]=='1';
            putintogrid(a[2][0],i+2,j);
            putintogrid(a[2][2],i+2,j+2);
            putintogrid(a[0][2],i,j+2);
        }else
        if(important2.size()==3)
            for(int i=0;i<3;i++)
                for(int j=0;j<3;j++)
                    putintogrid(a[i][j],max(0,szofg-7-(3-i)*10),max(0,szofg-7+(3-i)*10));
        else {
            putintogrid(a[0][0],0,0),putintogrid(a[2][2],k,k),putintogrid(a[2][0],k,0),putintogrid(a[0][2],0,k);
        }
        return howmanyislands(2*n+1);
    }
    if(k<5) {
        for(int i=0;i<2*n+1;i++)
            grid[i].reset();
        if(i&1||j&1) return a[0][0];
        int A=*--important.upper_bound(i);
        int B=*--important.upper_bound(j);
        if(max(i-A,j-B)==10-2*k-2||(!A&&!B&&max(i,j)==*++important.begin()-2-2*k)) {
            grid[i][j]=a[0][0][0]=='1';
            grid[i+1][j]=a[1][0][0]=='1';
            grid[i][j+1]=a[0][1][0]=='1';
            grid[i+1][j+1]=a[1][1][0]=='1';
            grid[i+2][j+1]=a[2][1][0]=='1';
            grid[i+1][j+2]=a[1][2][0]=='1';
            putintogrid(a[2][0],i+2,j);
            putintogrid(a[2][2],i+2,j+2);
            putintogrid(a[0][2],i,j+2);
        } else return a[0][0];
        return encode_grid(i+!!i*(k==4),j+!!j*(k==4));
    }
    int transport[30][30][15];
    for(auto i:important2){
        for(auto j:important2){
            int CC=5;
            int origi=i;
            int origj=j;
            if(!i){
                while(j)transport[0][j-=2][CC++]=1;
            }else if(!j) {
                while(i)transport[i-=2][0][CC++]=2;
            }else if(i==j){
                while(i)transport[i-=2][j-=2][CC++]=3;
            } else if(i<j) {
                while(i>2)transport[i-=2][j-=2][CC++]=3;
                transport[--i][j-=2][CC++]=4;
                while(j>2)transport[i-=2][j-=2][CC++]=1;
            } else {
                while(i>2)transport[i-=2][j-=2][CC++]=3;
                transport[--i][j-=2][CC++]=5;
                while(j>2)transport[i-=2][j-=2][CC++]=2;
            }
            i=origi;
            j=origj;
        }
    }
    if(i==0&&j==0)return a[0][0];
    if(transport[i][j][k]){
        if(transport[i][j][k]==1)
            return a[0][2];
        if(transport[i][j][k]==2)
            return a[2][0];
        if(transport[i][j][k]==3)
            return a[2][2];
        if(transport[i][j][k]==4)
            return a[1][2];
        if(transport[i][j][k]==5)
            return a[2][1];
        return a[0][0];
    }
    int x=max(i,j);
    if(x==1&&important2.size()==3) {
        int c=4+*++important2.begin()/2;
        if(c==k){
            return a[i][j];
        }
    }
    return a[0][0];
}

Compilation message

mars.cpp: In function 'void putintogrid(std::string, int, int)':
mars.cpp:34:46: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   34 |         grid[i+I][j+J]=grid[i+I][j+J]|a[CC++]=='1';
mars.cpp: In function 'std::string process(std::vector<std::vector<std::__cxx11::basic_string<char> > >, int, int, int, int)':
mars.cpp:130:41: warning: array subscript -1 is below array bounds of 'int [30][30][15]' [-Warray-bounds]
  130 |                 while(j>2)transport[i-=2][j-=2][CC++]=2;
      |                           ~~~~~~~~~~~~~~^
mars.cpp:111:9: note: while referencing 'transport'
  111 |     int transport[30][30][15];
      |         ^~~~~~~~~
mars.cpp:126:41: warning: array subscript -1 is below array bounds of 'int [30][30][15]' [-Warray-bounds]
  126 |                 while(j>2)transport[i-=2][j-=2][CC++]=1;
      |                           ~~~~~~~~~~~~~~^
mars.cpp:111:9: note: while referencing 'transport'
  111 |     int transport[30][30][15];
      |         ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
29 Correct 85 ms 4252 KB Output is correct
30 Incorrect 14 ms 776 KB Incorrect
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
29 Correct 85 ms 4252 KB Output is correct
30 Incorrect 14 ms 776 KB Incorrect
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
29 Correct 85 ms 4252 KB Output is correct
30 Incorrect 14 ms 776 KB Incorrect
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
29 Correct 85 ms 4252 KB Output is correct
30 Incorrect 14 ms 776 KB Incorrect
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
29 Correct 85 ms 4252 KB Output is correct
30 Incorrect 14 ms 776 KB Incorrect
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2996 KB Output is correct
2 Correct 7 ms 2916 KB Output is correct
3 Correct 7 ms 3272 KB Output is correct
4 Correct 6 ms 3068 KB Output is correct
5 Correct 8 ms 3088 KB Output is correct
6 Correct 7 ms 2928 KB Output is correct
7 Correct 8 ms 3172 KB Output is correct
8 Correct 12 ms 3184 KB Output is correct
9 Correct 9 ms 3764 KB Output is correct
10 Correct 11 ms 3172 KB Output is correct
11 Correct 13 ms 3096 KB Output is correct
12 Correct 8 ms 3352 KB Output is correct
13 Correct 10 ms 3104 KB Output is correct
14 Correct 19 ms 4164 KB Output is correct
15 Correct 28 ms 4080 KB Output is correct
16 Correct 28 ms 3736 KB Output is correct
17 Correct 31 ms 3928 KB Output is correct
18 Correct 30 ms 3620 KB Output is correct
19 Correct 24 ms 3884 KB Output is correct
20 Correct 27 ms 4332 KB Output is correct
21 Correct 43 ms 3844 KB Output is correct
22 Correct 63 ms 4408 KB Output is correct
23 Correct 58 ms 4108 KB Output is correct
24 Correct 57 ms 4096 KB Output is correct
25 Correct 69 ms 4612 KB Output is correct
26 Correct 64 ms 4144 KB Output is correct
27 Correct 59 ms 4088 KB Output is correct
28 Correct 69 ms 4200 KB Output is correct
29 Correct 85 ms 4252 KB Output is correct
30 Incorrect 14 ms 776 KB Incorrect
31 Halted 0 ms 0 KB -