답안 #223185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223185 2020-04-15T04:40:42 Z Autoratch Dango Maker (JOI18_dango_maker) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ti tuple<int,int,int,bool> 

const int N = 3010;

int m,n,ans;
char c[N][N];
bool v[N][N],h[N][N];
int cv[N][N],ch[N][N];
set<ti> s;

void del(ti a,ti tt)
{
    auto &[c,x,y,t] = a;
    if(t==0)
    {
        auto it = s.find({ch[x-2][y+2],x-2,y+2,1});
        if(it!=s.end() and *it!=tt) ch[x-2][y+2]--,s.erase(it),ans++;
        else if(x>2 and y+2<=n and ch[x-2][y+2])
        {
            ch[x-2][y+2]--;
            if(ch[x-2][y+2]==1) s.insert({ch[x-2][y+2],x-2,y+2,1});
        }
        it = s.find({ch[x-1][y+1],x-1,y+1,1});
        if(it!=s.end() and *it!=tt) ch[x-1][y+1]--,s.erase(it),ans++;
        else if(x>1 and y+1<=n and ch[x-1][y+1]
        {
            ch[x-1][y+1]--;
            if(ch[x-1][y+1]==1) s.insert({ch[x-1][y+1],x-1,y+1,1});
        }
        it = s.find({ch[x][y],x,y,1});
        if(it!=s.end() and *it!=tt) ch[x][y]--,s.erase(it),ans++;
        else if(ch[x][y])
        {
            ch[x][y]--;
            if(ch[x][y]==1) s.insert({ch[x][y],x,y,1});
        }
        cv[x][y] = 0;
    }
    else
    {
        auto it = s.find({cv[x+2][y-2],x+2,y-2,0});
        if(it!=s.end() and *it!=tt) cv[x+2][y-2]--,s.erase(it),ans++;
        else if(x+2<=m and y>2 and cv[x+2][y-2])
        {
            cv[x+2][y-2]--;
            if(cv[x+2][y-2]==1) s.insert({cv[x+2][y-2],x+2,y-2,0});
        }
        it = s.find({cv[x+1][y-1],x+1,y-1,0});
        if(it!=s.end() and *it!=tt) cv[x+1][y-1]--,s.erase(it),ans++;
        else if(x+1<=m and y>1 and cv[x+1][y-1])
        {
            cv[x+1][y-1]--;
            if(cv[x+1][y-1]==1) s.insert({cv[x+1][y-1],x+1,y-1,0});
        }
        it = s.find({cv[x][y],x,y,0});
        if(it!=s.end() and *it!=tt) cv[x][y]--,s.erase(it),ans++;
        else if(cv[x][y])
        {
            cv[x][y]--;
            if(cv[x][y]==1) s.insert({cv[x][y],x,y,0});
        }
        ch[x][y] = 0;
    }
    s.erase({c,x,y,t}); 
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> m >> n;
    for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) cin >> c[i][j];
    for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) 
    {
        if(i>2 and c[i-2][j]=='R' and c[i-1][j]=='G' and c[i][j]=='W') v[i][j] = 1;
        if(j>2 and c[i][j-2]=='R' and c[i][j-1]=='G' and c[i][j]=='W') h[i][j] = 1;
    }
    for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++)
    {
        if(v[i][j]) cv[i][j] = (int)h[i][j]+(int)h[i-1][j+1]+(int)h[i-2][j+2];
        if(h[i][j]) ch[i][j] = (int)v[i][j]+(int)v[i+1][j-1]+(int)v[i+2][j-2];
        if(v[i][j]){ if(!cv[i][j]) ans++; else if(cv[i][j]==1) s.insert({cv[i][j],i,j,0}); }
        if(h[i][j]){ if(!ch[i][j]) ans++; else if(ch[i][j]==1) s.insert({ch[i][j],i,j,1}); }
    }
    while(!s.empty())
    {
        ti tt = (*s.begin());
        auto &[c,x,y,t] = tt;
        ans++;
        if(t==0)
        {
            cv[x][y] = 0;
            if(x>2 and y+2<=n and ch[x-2][y+2]) del({ch[x-2][y+2],x-2,y+2,1},tt);
            if(x>1 and y+1<=n and ch[x-1][y+1]) del({ch[x-1][y+1],x-1,y+1,1},tt);
            if(ch[x][y]) del({ch[x][y],x,y,1},tt);
        }
        else
        {
            ch[x][y] = 0;
            if(x+2<=m and y>2 and cv[x+2][y-2]) del({cv[x+2][y-2],x+2,y-2,0},tt);
            if(x+1<=m and y>1 and cv[x+1][y-1]) del({cv[x+1][y-1],x+1,y-1,0},tt);
            if(cv[x][y]) del({cv[x][y],x,y,0},tt);
        }
        s.erase({c,x,y,t});
    }
    cout << ans;
}

Compilation message

dango_maker.cpp: In function 'void del(std::tuple<int, int, int, bool>, std::tuple<int, int, int, bool>)':
dango_maker.cpp:15:11: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     auto &[c,x,y,t] = a;
           ^
dango_maker.cpp:27:17: warning: init-statement in selection statements only available with -std=c++1z or -std=gnu++1z
         else if(x>1 and y+1<=n and ch[x-1][y+1]
                 ^
dango_maker.cpp:28:9: error: expected ';' before '{' token
         {
         ^
dango_maker.cpp:27:32: warning: statement has no effect [-Wunused-value]
         else if(x>1 and y+1<=n and ch[x-1][y+1]
                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:32:38: error: expected ')' before ';' token
         it = s.find({ch[x][y],x,y,1});
                                      ^
dango_maker.cpp:32:12: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
         it = s.find({ch[x][y],x,y,1});
         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:32:12: error: could not convert '(it = s.std::set<std::tuple<int, int, int, bool> >::find(std::tuple<int, int, int, bool>(ch[x][y], (* & x), (* & y), 1)))' from 'std::_Rb_tree_const_iterator<std::tuple<int, int, int, bool> >' to 'bool'
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:90:15: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
         auto &[c,x,y,t] = tt;
               ^