QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#35800#4250. Marswe_wendys0 0ms0kbC++2310.4kb2022-06-19 16:34:342024-04-28 07:14:24

Judging History

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

  • [2024-04-28 07:14:24]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-03 23:07:09]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2022-06-19 16:34:34]
  • 提交

answer

//http://qoj.ac/contest/948/problem/4250
//#pragma GCC optimize("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

template<class K> using sset =  tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll ceil0(ll a, ll b) {
    return a / b + ((a ^ b) > 0 && a % b);
}

void setIO() {
    ios_base::sync_with_stdio(0); cin.tie(0);
}

string setval(string s, int l, int r, int v){
    string ret = s;
    for(int i = l; i <= r; i++){
        if(i - l >= 30) ret[i] = '0';
        else ret[i] = '0' + (bool)(v & (1 << (i - l)));
    }
    return ret;
}

int findval(string s, int l, int r){
    int ret = 0;
    for(int i = l; i <= r; i++) ret += ((s[i] - '0') << (i - l));
    return ret;
}

int par[10000];
bool in[10000];

int find(int x){
    if(x == par[x]) return x;
    return par[x] = find(par[x]);
}

int enc(int x, int y){
    return x*50 + y;
}

string process(vector<vector<string>> arr, int x, int y, int t, int n){
    int moves[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    int lim = 2*(n - t - 1);
    //if its completely within the border then it doesnt mattter
    if(x < lim && y < lim) {
        assert(arr[0][0].size() == 0);
        return arr[0][0]; 
    }
    //on the corner
    if(x == lim && y == lim){
        int m = t*2 + 1;
        for(int i = 0; i <= enc(m + 1, m + 1); i++) par[i] = i;
        //base case
        if(t == 0){
            int cnt = 0;
            for(int i = 0; i < m + 2; i++){
                for(int j = 0; j < m + 2; j++){
                    cnt += arr[i][j][0] == '1';
                }
            }
            for(int i = 0; i < m + 2; i++){
                for(int j = 0; j < m + 2; j++){
                    for(int k = 0; k < 4; k++){
                        int ii = i + moves[k][0], jj = j + moves[k][1];
                        if(ii >= 0 && jj >= 0 && ii < m + 2 && jj < m + 2){
                            if(arr[i][j][0] == '1' && arr[ii][jj][0] == '1' && find(enc(ii, jj)) != find(enc(i, j))){
                                par[find(enc(ii, jj))] = find(enc(i, j));
                                cnt--;
                            }
                        }
                    }
                }
            }
            if(n == 1) return setval(arr[0][0], 0, 99, cnt);
            bool prv = false;
            vector<int> v;
            //right to left
            for(int i = 2; i >= 0; i--){
                if(arr[0][i][0] == '1' && !prv) v.pb(find(enc(0, i))), prv = true;
                if(arr[0][i][0] == '0') prv = false;
            }
            //top to bottom
            for(int i = 1; i <= 2; i++){
                if(arr[i][0][0] == '1' && !prv) v.pb(find(enc(i, 0))), prv = true;
                if(arr[i][0][0] == '0') prv = false;
            }
            memset(in, false, sizeof(in));
            stack<int> s;
            string ret = "";
            for(int i = 0; i < 100; i++) ret += "0";
            for(int i = 0; i < v.size(); i++){
                if(!s.empty() && in[find(v[i])]){
                    while(find(v[s.top()]) != find(v[i])){
                        ret[s.top()*2 + 1] = '1';
                        s.pop();
                    }
                    s.pop();
                    s.push(i);
                }
                else {
                    ret[i*2] = '1';
                    in[find(v[i])] = true;
                    s.push(i);
                }
            }
            while(s.size()){
                ret[s.top()*2 + 1] = '1';
                s.pop();
            }
            ret = setval(ret, 90, 99, cnt);
            return ret;
        }
        //construct the grid
        int grid[m + 2][m + 2];
        memset(grid, 0, sizeof(grid));
        //2x2 square
        for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) grid[i][j] = arr[i][j][0] - '0';
        //2xM and Mx2 rectangle
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                grid[j][i + 2] = arr[0][2][j*m + i] - '0';
                grid[i + 2][j] = arr[2][0][j*m + i] - '0';
            }
        }
        //top left border
        for(int i = 0; i < m; i++){
            grid[2][i + 2] = arr[1][2][m + i] - '0';
            grid[i + 2][2] = arr[2][1][m + i] - '0';
        }
        //merge all adjacent cells on outer border
        /*for(int i = 0; i < m + 2; i++){
            for(int j = 0; j < m + 2; j++){
                cout << grid[i][j] << " ";
            }
            cout << endl;
        }*/
        int cnt = findval(arr[2][2], 90, 99);
        for(int i = 0; i < m + 2; i++){
            for(int j = 0; j < 2; j++){
                cnt += grid[j][i];
                cnt += grid[i][j];
            }
        }
        //overcounts some grids
        cnt -= grid[0][0];
        cnt -= grid[0][1];
        cnt -= grid[1][0];
        cnt -= grid[1][1];
        for(int i = 0; i < m + 2; i++){
            if(grid[0][i] && grid[1][i] && find(enc(0, i)) != find(enc(1, i))){
                par[find(enc(0, i))] = find(enc(1, i));
                cnt--;
            }
            if(grid[i][0] && grid[i][1] && find(enc(i, 0)) != find(enc(i, 1))){
                par[find(enc(i, 0))] = find(enc(i, 1));
                cnt--;
            }
            for(int j = 0; j < 2; j++){
                if(i < m + 1 && grid[i][j] && grid[i + 1][j] && find(enc(i, j)) != find(enc(i + 1, j))){
                    par[find(enc(i, j))] = find(enc(i + 1, j));
                    cnt--;
                }
                if(i < m + 1 && grid[j][i] && grid[j][i + 1] && find(enc(j, i)) != find(enc(j, i + 1))){
                    par[find(enc(j, i))] = find(enc(j, i + 1));
                    cnt--;
                }
            }
        }
        //merge all adjacent cells on inner border
        for(int i = m; i >= 2; i--){
            if(grid[2][i] && grid[2][i + 1] && find(enc(2, i)) != find(enc(2, i + 1))){
                par[find(enc(2, i))] = find(enc(2, i + 1));
            }
        }
        for(int i = 3; i <= m + 1; i++){
            if(grid[i][2] && grid[i - 1][2] && find(enc(i, 2)) != find(enc(i - 1, 2))){
                par[find(enc(i, 2))] = find(enc(i - 1, 2));
            }
        }
        //decode the components of inner grid
        vector<int> vv;
        bool prv = false;
        //right to left
        for(int i = m + 1; i >= 2; i--){
            if(grid[2][i] && !prv) vv.pb(find(enc(2, i))), prv = true;
            if(!grid[2][i]) prv = false;
        }
        //top to bottom
        for(int i = 3; i <= m + 1; i++){
            if(grid[i][2] && !prv) vv.pb(find(enc(i, 2))), prv = true;
            if(!grid[i][2]) prv = false;
        }
        stack<int> s;
        int id[vv.size()];
        for(int i = 0; i < vv.size(); i++){
            //open an interval
            if(arr[2][2][2*i] == '1'){
                s.push(i);
            }
            id[i] = s.top();
            for(int j = 0; j < i; j++){
                if(id[j] == id[i]){
                    par[find(vv[j])] = find(vv[i]);
                }
            }
            //close an interval
            if(arr[2][2][2*i + 1] == '1'){
                s.pop();
            }
        }
        //merge edges between grids
        for(int i = 2; i < m + 2; i++){
            if(grid[1][i] && grid[2][i] && find(enc(1, i)) != find(enc(2, i))){
                par[find(enc(1, i))] = find(enc(2, i));
                cnt--;
            }
            if(grid[i][1] && grid[i][2] && find(enc(i, 1)) != find(enc(i, 2))){
                par[find(enc(i, 1))] = find(enc(i, 2));
                cnt--;
            }
        }
        //encode the components of the current grid
        prv = false;
        vector<int> v;
        //right to left
        for(int i = m + 1; i >= 0; i--){
            if(grid[0][i] && !prv) v.pb(enc(0, i)), prv = true;
            if(!grid[0][i]) prv = false;
        }
        //top to bottom
        for(int i = 1; i <= m + 1; i++){
            if(grid[i][0] && !prv) v.pb(enc(i, 0)), prv = true;
            if(!grid[i][0]) prv = false;
        }
        memset(in, false, sizeof(in));
        assert(s.empty());
        string ret = "";
        for(int i = 0; i < 100; i++) ret += "0";
        if(t == n - 1){
            return setval(ret, 0, 100, cnt);
        }
        //i*2 - open, i*2 + 1 - close
        for(int i = 0; i < v.size(); i++){
            //close the interval
            if(!s.empty() && in[find(v[i])]){
                while(find(v[s.top()]) != find(v[i])){
                    ret[s.top()*2 + 1] = '1';
                    s.pop();
                }
                s.pop();
                s.push(i);
            }
            //open an interval
            else {
                ret[i*2] = '1';
                in[find(v[i])] = true;
                s.push(i);
            }
        }
        while(!s.empty()){
            ret[s.top()*2 + 1] = '1';
            s.pop();
        }
        ret = setval(ret, 90, 99, cnt);
        return ret;
    } else {
        //if its on the bottom border, needs to be rotated
        if(x == lim){
            for(int i = 0; i < 3; i++){
                for(int j = 0; j < i; j++){
                    swap(arr[i][j], arr[j][i]);
                }
            }
        }
        //if right border stores everything to the right and down two rows
        //0         2*t + 2
        //2*t + 3   4*t + 6
        //if bottom border stores everything down and to the right two rows
        //0         2*t + 3
        //2*t + 2   4*t + 6
        string ret = "";
        for(int i = 0; i < 2; i++){
            for(int j = 0; j < 2; j++){
                ret += arr[i][j][0];
            }
            for(int j = 0; j < 2*t + 1; j++) ret += arr[i][2][j];
        }
        while(ret.length() < 100) ret += "0";
        return ret;
    }
}

详细

Subtask #1:

score: 0
Instance #0 Runtime Error

Test #1:

score: 0
Instance #0 Runtime Error

input:

224bb858-b13b-5e97-cbba-4a10b0455e79
2
934 389 626 424
1010111000011100001101110100011101000000010110011011101010001010000001011000010011000001111011111111 1101011000101100110110100011110010000010000100001010001110101111010000100001110000001110110011001010 0110111001011000110000110000011011100110001...

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


input:

224bb858-b13b-5e97-cbba-4a10b0455e79
-1

output:


result:


Subtask #2:

score: 0
Skipped

Subtask #3:

score: 0
Skipped

Subtask #4:

score: 0
Skipped

Subtask #5:

score: 0
Skipped

Subtask #6:

score: 0
Skipped

Subtask #7:

score: 0
Skipped

Subtask #8:

score: 0
Skipped

Subtask #9:

score: 0
Skipped

Subtask #10:

score: 0
Skipped