QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194992#6677. Puzzle: SashiganeUFRJ#WA 0ms3564kbC++205.9kb2023-09-30 23:59:582023-09-30 23:59:58

Judging History

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

  • [2023-09-30 23:59:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2023-09-30 23:59:58]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using lint = int64_t;

#define TOPLEFT 0
#define TOPRIGHT 1
#define BOTLEFT 2
#define BOTRIGHT 3

vector<pair<int,int>> bordersPos(4);
vector<vector<bool>> m;
int n, whiteNum;
vector<vector<int>> ans;

bool isValid(pair<int,int> p) {
    return p.first >= 0 and p.first < n and p.second >= 0 and p.second < n;
}

void TopLeftToBotRight() {
    int x, y;
    x = bordersPos[TOPLEFT].first - 1;
    y = bordersPos[TOPLEFT].second - 1;
    if(!isValid({x, y})) return;
    if(m[x][y]) return;
    int leftCount = 0;
    int botCount = 0;
    for(int i = y; i <= bordersPos[TOPRIGHT].second and i < n; i++) {
        if(!isValid({x, i}) or m[x][i] == 1) break;
        leftCount++;
        whiteNum--;
        m[x][i] = 1;
    }
    for(int i = x+1; i <= bordersPos[BOTLEFT].first and i < n; i++) {
        if(!isValid({i, y}) or m[i][y] == 1) break;
        botCount++;
        whiteNum--;
        m[i][y] = 1;
    }
    ans.push_back({x, y, leftCount - 1, botCount});
}

void BotRightToTopLeft() {
    int x, y;
    x = bordersPos[BOTRIGHT].first + 1;
    y = bordersPos[BOTRIGHT].second + 1;
    if(!isValid({x, y})) return;
    int leftCount = 0;
    int botCount = 0;
    if(m[x][y]) return;
    for(int i = y; i >= bordersPos[BOTLEFT].second and i >= 0; i--) {
        if(!isValid({x, i}) or m[x][i] == 1) break;
        leftCount++;
        whiteNum--;
        m[x][i] = 1;
    }
    for(int i = x-1; i >= bordersPos[TOPRIGHT].first and i >= 0; i--) {
        if(!isValid({i, y}) or m[i][y] == 1) break;
        botCount++;
        whiteNum--;
        m[i][y] = 1;
    }
    ans.push_back({x, y, leftCount - 1, -botCount});
}

void TopRightToBotLeft() {
    int x, y;
    x = bordersPos[TOPRIGHT].first - 1;
    y = bordersPos[TOPRIGHT].second + 1;
    if(!isValid({x, y})) return;
    if(m[x][y]) return;
    int leftCount = 0;
    int botCount = 0;
    for(int i = y; i >= bordersPos[BOTLEFT].second and i >= 0; i--) {
        if(!isValid({x, i}) or m[x][i] == 1) break;
        leftCount++;
        whiteNum--;
        m[x][i] = 1;
    }
    for(int i = x+1; i <= bordersPos[BOTRIGHT].first and i < n; i++) {
        if(!isValid({i, y}) or m[i][y] == 1) break;
        botCount++;
        whiteNum--;
        m[i][y] = 1;
    }
    ans.push_back({x, y, -leftCount - 1, botCount});
}

void BotLeftToTopRight() {
    int x, y;
    x = bordersPos[BOTLEFT].first + 1;
    y = bordersPos[BOTLEFT].second - 1;
    if(!isValid({x, y})) return;
    if(m[x][y]) return;
    int leftCount = 0;
    int botCount = 0;
    // cout << x << " " << y << endl;
    // cout <<  bordersPos[BOTRIGHT].first << " " <<  bordersPos[BOTRIGHT].second << endl;
    for(int i = y; i <= bordersPos[BOTRIGHT].second and i < n; i++) {
        if(!isValid({x, i}) or m[x][i] == 1) break;
        leftCount++;
        whiteNum--;
        m[x][i] = 1;
    }
    for(int i = x-1; i >= bordersPos[TOPLEFT].first and i >= 0; i--) {
        if(!isValid({i, y}) or m[i][y] == 1) break;
        botCount++;
        whiteNum--;
        m[i][y] = 1;
    }
    ans.push_back({x, y, leftCount - 1, -botCount});
}   


void print() {
    cout << "Print: " << endl;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << m[i][j] << " "; 
        }
        cout << endl;
    }
}

void updateBorderTopLeft() {
    int x = bordersPos[TOPLEFT].first;
    int y = bordersPos[TOPLEFT].second;
    if(isValid(bordersPos[TOPLEFT]) && !m[x][y]) return;
    while(m[x][y]) {
        if(isValid({x-1, y}) and m[x-1][y]) x--;
        else if(isValid({x, y-1}) and m[x][y-1]) y--;
        else break;
    }
    bordersPos[TOPLEFT] = {x, y};
}

void updateBorderTopRight() {
    int x = bordersPos[TOPRIGHT].first;
    int y = bordersPos[TOPRIGHT].second;
    if(isValid(bordersPos[TOPRIGHT]) && !m[x][y]) return;
    while(m[x][y]) {
        if(isValid({x-1, y}) and m[x-1][y]) x--;
        else if(isValid({x, y+1}) and m[x][y+1]) y++;
        else break;
    }
    bordersPos[TOPRIGHT] = {x, y};
}

void updateBorderBotLeft() {
    int x = bordersPos[BOTLEFT].first;
    int y = bordersPos[BOTLEFT].second;
    if(isValid(bordersPos[BOTLEFT]) && !m[x][y]) return;
    while(m[x][y]) {
        if(isValid({x+1, y}) and m[x+1][y]) x++;
        else if(isValid({x, y-1}) and m[x][y-1]) y--;
        else break;
    }
    bordersPos[BOTLEFT] = {x, y};
}

void updateBorderBotRight() {
    int x = bordersPos[BOTRIGHT].first;
    int y = bordersPos[BOTRIGHT].second;
    
    if(isValid(bordersPos[BOTRIGHT]) && !m[x][y]) return;
    while(m[x][y]) {
        if(isValid({x+1, y}) and m[x+1][y]) x++;
        else if(isValid({x, y+1}) and m[x][y+1]) y++;
        else break;
    }
    bordersPos[BOTRIGHT] = {x, y};
}

void updateBorders() {
    updateBorderBotLeft();
    updateBorderTopLeft();
    updateBorderBotRight();
    updateBorderTopRight();
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    int x, y;
    cin >> n >> x >> y;
    x--, y--;
    m.assign(n, vector<bool>(n));
    m[x][y] = 1;
    
    bordersPos[TOPLEFT] = {x, y};
    bordersPos[TOPRIGHT] = {x, y};
    bordersPos[BOTLEFT] = {x, y};
    bordersPos[BOTRIGHT] = {x, y};
    
    whiteNum = n*n - 1;
    while(whiteNum) {
        TopLeftToBotRight();
        updateBorders();
        // print();
        
        BotRightToTopLeft();
        updateBorders();
        // print();
        
        TopRightToBotLeft();
        updateBorders();
        // print();
        
        BotLeftToTopRight();
        updateBorders();
        // print();
    }

    cout << "Yes" << "\n";
    cout << ans.size() << "\n";
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][3] << " " << ans[i][2] << "\n";
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

input:

5 3 4

output:

Yes
4
2 3 1 1
4 5 -2 2
5 2 -3 3
1 1 4 4

result:

wrong answer L shape #2 out of bounds. (test case 1)