QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266706#4323. 德州消消乐jzhCompile Error//C++207.4kb2023-11-26 16:57:292023-11-26 16:57:30

Judging History

你现在查看的是最新测评结果

  • [2023-11-26 16:57:30]
  • 评测
  • [2023-11-26 16:57:29]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
const int N = 60;
int a[N][N], tmp[N][N];
int sp[N][N];
bool vis[N][N];
bool vissp[N][N];
int tmpsp[N][N];
int n, m;
set<pii> elim() {
    set<pii> ans;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == 0)continue;
            if (a[i - 1][j] == a[i][j] && a[i][j] == a[i + 1][j]) {
                ans.insert({i - 1, j});
                ans.insert({i, j});
                ans.insert({i + 1, j});
            }
            if (a[i][j - 1] == a[i][j] && a[i][j] == a[i][j + 1]) {
                ans.insert({i, j - 1});
                ans.insert({i, j});
                ans.insert({i, j + 1});
            }
        }
    }
    return ans;
}

int dfs(pii pos, int col) {
    if (vis[pos.first][pos.second] || a[pos.first][pos.second] != col)return 0;
    vis[pos.first][pos.second] = true;
    const int x[] = {1, -1, 0, 0}, y[] = {0, 0, 1, -1};
    int cnt = 1;
    for (int i = 0; i < 4; i++) {
        int nx = pos.first + x[i], ny = pos.second + y[i];
        cnt += dfs({nx, ny}, col);
    }
    return cnt;
}


void fall() {
    memset(tmp, 0, sizeof(tmp));
    memset(tmpsp, 0, sizeof(tmpsp));
    for (int j = 1; j <= m; j++) {
        int ci = n;
        for (int i = n; i >= 1; i--) {
            if (a[i][j] != 0) {
                tmp[ci][j] = a[i][j];
                tmpsp[ci][j] = sp[i][j];
                ci--;
            }
        }
    }
    swap(tmp, a);
    swap(tmpsp, sp);
}

vector<set<int>> maincol;

queue<pii> q;
long long c1, c2, c3, c4;
bool is_in(pii p) {
    return 1 <= p.first && p.first <= n && 1 <= p.second && p.second <= m;
}
void spelim(int turn) {
    memset(vissp, 0, sizeof(vissp));
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        if (vissp[p.first][p.second] || a[p.first][p.second] == 0)continue;
        vissp[p.first][p.second] = true;
        int u = sp[p.first][p.second];
        c1 += ( (turn+1) * a[p.first][p.second]);
        int tmpc = a[p.first][p.second];
        a[p.first][p.second] = 0;

        if (u == 1) {
            for (int i = 1; i <= m; i++) {
                q.push({p.first, i});
            }
        } else if (u == 2) {
            for (int i = 1; i <= n; i++) {
                q.push({i, p.second});
            }
        } else if (u == 3) {
            for (int i = 1; i <= m; i++) {
                q.push({p.first, i});
            }
            for (int i = 1; i <= n; i++) {
                q.push({i, p.second});
            }
        } else if (u == 4) {
            for (int i = -1; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    pii np = {p.first + i, p.second + j};
                    if (is_in(np)) {
                        q.push(np);
                    }
                }
            }
        } else if (u == 5) {
            for (int i = -2; i <= 2; i++) {
                for (int j = -2; j <= 2; j++) {
                    pii np = {p.first + i, p.second + j};
                    if (is_in(np)) {
                        q.push(np);
                    }
                }
            }
        } else if (u == 6) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (a[i][j] == tmpc) {
                        q.push({i, j});
                    }
                }
            }
        }
    }
}

void show() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << a[i][j] << "(" << sp[i][j] <<") ";
        }
        cout << endl;
    }
};

typedef long long ll;

bool simop(pii &p1, pii &p2) {
    if (a[p1.first][p1.second] == 0 || a[p2.first][p2.second] == 0) {
        return false;
    }
    if(abs(p1.first - p2.first) + abs(p1.second - p2.second) != 1){
        return false;
    }
    swap(a[p1.first][p1.second], a[p2.first][p2.second]);
    swap(sp[p1.first][p1.second],sp[p2.first][p2.second]);
    bool lst = true;
    int turn = 0;
    while (lst) {
        auto res = elim();
        lst = (!res.empty());
 if(turn == 0 && col.empty()){
            swap(a[p1.first][p1.second], a[p2.first][p2.second]);
            swap(sp[p1.first][p1.second],sp[p2.first][p2.second]);
            return false;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                vis[i][j] = 1;
            }
        }
        for(auto p:res){
            vis[p.first][p.second] = 0;
        }
        for (auto p: res) {
            ll cnt = dfs(p, a[p.first][p.second]);
            if (cnt >= 3)c3 +=  50 * (cnt - 3) * (cnt - 3);
        }
        set<int> col;
        for (auto p: res) {
            col.insert(a[p.first][p.second]);
        }
       

        if(turn==0 && col.size() > 0 ){
            maincol.push_back(col);
        }

        while (!q.empty())q.pop();
        for (auto p: res) {
            q.push(p);
        }
        spelim(turn);
        fall();
        turn++;
    }
    if(turn>=2) c2 += 80 * (turn - 2) * (turn - 2);
    return true;
}

bool all_empty() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j])return false;
        }
    }
    return true;
}

int k;
int cnt[N];

ll dfscol(int u) {
    if (u == 5) {
        int p1 = 0, p2 = 0;
        int i1 = 0 , i2 = 0;
        for (int i = 1; i <= k; i++) {
            if (cnt[i] >= p1) {
                p2 = p1;
                i2 = i1;
                p1 = cnt[i];
                i1 = i;
            } else if (cnt[i] >= p2) {
                p2 = cnt[i];
                i2 = i;
            }
        }

        if (p1 == 5) {
            return 1000 + i1 * 10;
        } else if (p1 == 4) {
            return 750 + i1 * 5;
        } else if (p1 == 3 && p2 == 2) {
            return 500 + 3 * i1 + i2;
        } else if (p1 == 3 && p2 == 1) {
            return 300 + 3 * i1;
        } else if (p1 == 2 && p2 == 2) {
            return 200 + 2 * max(i1, i2) + min(i1, i2);
        } else if (p1 == 2 && p2 == 1) {
            return 100 + 2 * i1;
        } else {
            return 50 + i1;
        }
    }
    ll ans = -1e18;
    //cout <<" siz " << maincol[u].size() <<" on " << u << endl;
    for (int c: maincol[u]) {
        cnt[c]++;
        ans = max(ans, dfscol(u + 1));
        cnt[c]--;
    }
    return ans;
}


int main() {

    ios::sync_with_stdio(false);

    int num;
    cin >> n >> m >> k >> num;

    bool b1 = true;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> sp[i][j];
        }
    }

    for (int i = 1; i <= num; i++) {
        pii p1, p2;
        cin >> p1.first >> p1.second >> p2.first >> p2.second;
        //cout << " on sim " << p1.first << " " << p1.second << endl;
        bool sud = simop(p1, p2);
        b1 &= sud;
       // cout << " cur is " << c1 << "," << c2 << "," << c3 << " and " << c1 + c2 + c3 << endl;
        if (maincol.size() == 5) {
          //  cout <<" counting " << endl;
            c4 += dfscol(0);
            maincol.clear();
        }

    }

    ll ans = c1 + c2 + c3 + c4;
    if (b1) ans += 1000;
    if (all_empty()) ans += 10000;

    cout << ans;

}

詳細信息

answer.code: In function ‘bool simop(pii&, pii&)’:
answer.code:151:18: error: ‘col’ was not declared in this scope; did you mean ‘cosl’?
  151 |  if(turn == 0 && col.empty()){
      |                  ^~~
      |                  cosl