QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#863799#9714. A Colorful GridIllusionaryDominanceWA 1ms9928kbC++204.8kb2025-01-19 22:43:192025-01-19 22:43:19

Judging History

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

  • [2025-01-19 22:43:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9928kb
  • [2025-01-19 22:43:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int N = 1e5+5;
int f[N][2], last[N][2];
map<int, int> a[N];
int rig[N], lef[N];
bool con[N];

char trans(char x)
{
    if (x == 'D') return 'R';
    if (x == 'U') return 'L';
    if (x == 'R') return 'D';
    if (x == 'L') return 'U';
    return 'X';
}

bool sol(int n, int m, vector<pair<int,int>> X1, vector<pair<int,int>> X0, bool flx, bool tr)
{   
    // cerr << " ------------------ \n";
    vector<pair<int,int>> X[2] = {X0, X1};
    vector<pair<int,int>> fg;
    int nowr = 0;
    for (int i = 0; i < X[1].size(); ++i)
    {
        auto [l, r] = X[1][i];
        int j = i;
        nowr = X[1][i].second;
        while (j + 1 < X[1].size() && X[1][j + 1].first <= nowr) nowr = max(nowr, X[1][++j].second);
        fg.push_back({X[1][i].first, nowr});
        i = j;
    }
    
    if (fg.size() == 1 && fg[0].first == 1 && fg[0].second == m) 
    {
        return 0;
    }
    for (int i = 0; i <= m; ++i) f[i][0] = f[i][1] = -1, con[i] = 0, a[i].clear(), last[i][0] = last[i][1] = -1, lef[i] = -3;
    f[0][0] = 0; f[0][1] = -1; f[1][0] = 0; f[1][1] = -1, last[1][0] = 0;
    
    for (auto [l, r] : X[0]) a[l][r] = 1, lef[r] = max(lef[r], l);
    for (auto [l, r] : fg) for (int j = l + 1; j <= r; ++j) con[j] = 1;
    
    // for (auto [l, r] : fg) cerr << l << "-" << r << " "; cerr << "\n";
    // for (auto [l, r] : X[0]) cerr << l << "|" << r << " "; cerr << "\n";
    
    bool notodd = n & 1;
    
    for (int i = 2; i <= m; ++i)
    {
        f[i][0] = f[i][1] = -1;
        // not put
        {
            if (f[i-1][1] != -1 && lef[i] < f[i-1][1])
            {
                f[i][1] = f[i-1][1];
                last[i][1] = 1;
            }
            // from f[i-1][0]
            else if (f[i-1][0] != -1 && lef[i] < f[i-1][0])
            {
                f[i][0] = f[i-1][0];
                last[i][0] = 0;
            }
        }
        // put
        if (!con[i])
        {
            int o = i & 1;
            if (f[i-2][o] != -1 && lef[i-1] < f[i-2][o] && lef[i-2] < f[i-2][o])
            {
                f[i][o] = i;
                last[i][o] = o;
            }
            if (f[i][o] != i && f[i-2][o^1] != -1 && !notodd && lef[i] < f[i-2][o^1] && lef[i] < f[i-2][o^1])
            {
                f[i][o] = i;
                last[i][o] = o ^ 1;
            }
        }
    }
    // cerr << f[7][1] << " " << last[7][1] << " " << f[5][1] << " " << f[4][0] << "\n";
    // cerr << f[0][0] << " " << f[0][1] << " " << f[1][0] << " " << f[1][1] << " " << f[2][0] << " " << f[2][1] << "\n";
    // return {0, vector<vector<char>>()};
    
    if (f[m][0] != -1 || f[m][1] != -1)
    {
        vector<vector<char>> ans(n+1, vector<char>(m+1, ' '));
        for (int i = m, j = (f[m][1] != -1); i >= 1; ) 
        {
            if (f[i][j] == i)
            {
                // cerr << i << " " << j << "\n";
                for (int k = 1; k <= n; ++k) ans[k][i-1] = 'R', ans[k][i] = 'L';
                j = last[i][j]; i -= 2;
            }
            else j = last[i][j], i -= 1;
        }
        for (int i = 2; i <= n; i += 2) for (int j = 1; j <= m; ++j) 
        if (ans[i][j] == ' ') ans[i][j] = 'U', ans[i-1][j] = 'D';
        for (int j = 1; j < m; ++j) if (ans[n][j] == ' ') ans[n][j] = 'R', ans[n][j+1] = 'L';
        cout << "Yes\n";
        if (tr)
        {
            for (int i = 1; i <= m; ++i, cout << "\n") for (int j = 1; j <= n; ++j) cout << trans(ans[j][i]);
        }
        else 
        {
            for (int i = 1; i <= n; ++i, cout << "\n") for (int j = 1; j <= m; ++j) cout << ans[i][j];
        }
        return 1;
    }
    return 0;
}

void solve()
{
    int n, m, k; cin >> n >> m >> k;
    vector<pair<int,int>> X[2], Y[2];
    bool flx = 0, fly = 0;
    for (int i = 1; i <= k; ++i) 
    {
        int x, y, v, w; cin >> x >> y >> v >> w;
        if (x > v) swap(x, v);
        if (y > w) swap(y, w);
        int o; cin >> o;
        if (o == 0 && x == v && y == w)
        {
            cout << "No\n";
            return ;
        }
        if (x != v) X[o].push_back({x, v});
        if (y != w) Y[o].push_back({y, w});
        if (x == v && y != w) flx = 1, X[o].push_back({x, v});
        if (y == w && x != v) fly = 1, Y[o].push_back({y, w});
    }
    sort(all(X[0])); sort(all(X[1])); sort(all(Y[0])); sort(all(Y[1]));
    if (sol(n, m, Y[1], Y[0], flx, 0)) return ;
    else if (sol(m, n, X[1], X[0], fly, 1)) return ;
    cout << "No\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int T; cin >> T;
    for (int i = 1; i <= T; ++i) 
    {
        cout << "Case #" << i << ": ";
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9928kb

input:

4
2 2 1
1 1 1 2 1
2 2 1
1 1 2 1 1
2 2 1
1 1 2 2 1
2 2 2
1 1 1 2 0
1 1 2 1 0

output:

Case #1: Yes
DD
UU
Case #2: Yes
RL
RL
Case #3: No
Case #4: No

result:

ok all accept

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 8664kb

input:

4
2 10 7
1 1 2 1 1
1 9 1 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0
2 10 6
1 1 2 1 1
1 8 1 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
2 10 6
1 1 2 2 0
1 8 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
2 10 7
1 1 2 2 0
1 9 2 10 1
1 2 2 4 0
1 3 2 5 0
1 4 2 6 0
1 5 2 7 0
1 6 2 8 0

output:

Case #1: Yes
DRLRLRLRLD
URLRLRLRLU
Case #2: Yes
DRLRLRLDDD
URLRLRLUUU
Case #3: Yes
DRLRLRLDDD
URLRLRLUUU
Case #4: Yes
DRLRLRLRLD
URLRLRLRLU

result:

wrong answer wrong output,type 2,Case 3,line 1