QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597241#9424. Stop the Castle 2ucup-team4906#WA 1ms3564kbC++143.5kb2024-09-28 17:20:572024-09-28 17:21:04

Judging History

This is the latest submission verdict.

  • [2024-09-28 17:21:04]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3564kb
  • [2024-09-28 17:20:57]
  • Submitted

answer

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
#define N 100010

int n, m, k;
int xc[N], yc[N], xo[N], yo[N];
map<int, set<pair<int, int>>>X, Y;
vector<int>V0, V1, V2;
vector<int>answer;
bool vst[N];
int ans;

void init()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i ++)
    {
        cin >> xc[i] >> yc[i];

        X[xc[i]].insert({yc[i], i});
        Y[yc[i]].insert({xc[i], i});
    }
    for (int i = 1; i <= m; i ++)
    {
        cin >> xo[i] >> yo[i];
        X[xo[i]].insert({yo[i], -i});
        Y[yo[i]].insert({xo[i], -i});
    }
}
void calcans()
{
    for (int i = 1; i <= n; i ++)
    {
        int x = xc[i], y = yc[i];
        auto it = X[x].lower_bound({y + 1, 0});
        if (it != X[x].end() && (*it).second > 0)ans ++;

        it = Y[y].lower_bound({x + 1, 0});
        if (it != Y[y].end() && (*it).second > 0)ans ++;
    }
}
void calc0()
{
    for (int i = 1; i <= m; i ++)
    {
        int x = xo[i], y = yo[i];
        auto itr1 = X[x].lower_bound({y + 1, 0}), itl1 = X[x].lower_bound({y, -1e9});
        if (!(itr1 == X[x].end() || itl1 == X[x].begin()))
        {
            itl1 --;
            if ((*itl1).second > 0 && (*itr1).second > 0) continue;
        }
        
        auto itr2 = Y[y].lower_bound({x + 1, 0}), itl2 = Y[y].lower_bound({x, -1e9});
        if (!(itr2 == Y[y].end() || itl2 == Y[y].begin()))
        {
            itl2 --;
            if ((*itl2).second > 0 && (*itr2).second > 0) continue;
        }

        vst[i] = 1;
        V0.push_back(i); X[xo[i]].erase({yo[i], -i}); Y[yo[i]].erase({xo[i], -i}); 
    }
}
void calc1()
{
    for (int i = 1; i <= m; i ++) if (!vst[i])
    {
        int num = 0;
        int x = xo[i], y = yo[i];
        auto itr1 = X[x].lower_bound({y + 1, 0}), itl1 = X[x].lower_bound({y, -1e9});
        if (!(itr1 == X[x].end() || itl1 == X[x].begin()))
        {
            itl1 --;
            if ((*itl1).second > 0 && (*itr1).second > 0) num ++;
        }
        
        auto itr2 = Y[y].lower_bound({x + 1, 0}), itl2 = Y[y].lower_bound({x, -1e9});
        if (!(itr2 == Y[y].end() || itl2 == Y[y].begin()))
        {
            itl2 --;
            if ((*itl2).second > 0 && (*itr2).second > 0) num ++;
        }

        if (num == 2)continue;
        vst[i] = 1;
        V1.push_back(i); X[xo[i]].erase({yo[i], -i}); Y[yo[i]].erase({xo[i], -i}); 
    }
}
void calc2()
{
    for (int i = 1; i <= m; i ++) if (!vst[i]){V2.push_back(i);}
}
void sol()
{
    init();
    calcans();
    calc0();
    calc1();
    calc2();

    while (k --)
    {
        if (!V0.empty())
        {
            int x = V0.back();
            answer.push_back(x);
            V0.pop_back();
            continue;
        }
        if (!V1.empty())
        {
            int x = V1.back();
            answer.push_back(x);
            ans ++;
            V1.pop_back();
            continue;
        }
        int x = V2.back();
        V2.pop_back();
        answer.push_back(x);
        ans += 2;
    }
    // cout << "ANS:" << endl;
    cout << ans << '\n';
    for (int x : answer)cout << x << ' '; cout << '\n';

    X.clear(); Y.clear();
    for (int i = 1; i <= m; i ++) vst[i] = 0;
    V0.clear(); V1.clear(); V2.clear();
    answer.clear();
    ans = 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T; cin >> T;
    while (T --) sol();

    return 0;
}

詳細信息

Test #1:

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

input:

3
8 6 4
1 3
2 1
2 6
4 1
4 7
6 1
6 3
6 6
2 3
3 1
4 3
4 6
5 2
6 4
3 2 1
10 12
10 10
10 11
1 4
1 5
1 3 2
1 1
2 1
2 2
2 3

output:

6
5 3 6 2 
2
2 
0
3 2 

result:

wrong answer Participant states the answer to be 6 but is actually 4 (test case 1)