QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#874497#9221. Missing Boundariesemersonjr02WA 37ms9600kbC++172.8kb2025-01-28 08:48:352025-01-28 08:48:37

Judging History

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

  • [2025-01-28 08:48:37]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:9600kb
  • [2025-01-28 08:48:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define sws std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define float long double
#define ld long double
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vpii vector<pair<int, int>> 
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define in(v) for(auto & x : v) cin >> x;
#define out(v) for(auto x : v) cout << x << ' ';
#define tiii tuple<int, int, int>

const int MAX = 3e5+1;
const int INF = INT32_MAX;
int MOD = 998244353;
const int LOG = 31;
const ld PI = acos(-1);
const int MINF = INT32_MIN;
vpii dirs = {{1, 0}, {-1, 0}};
vpii dirs1 = {{0, 1}, {0, -1}};

// Contest patrocinado por Summer

void solve() {

    int n, l, jokers = 0, needToBeFree = 0; cin >> n >> l;

    vpii sweep; // {iniInter, -1 ou 1 (l ou r)}
    vector<bool> marks(n);

    for(int i = 0; i < n; i++){

        int li, ri; cin >> li >> ri;

        if(ri == li && ri == -1) {jokers++; continue;}
        if(ri != -1) sweep.emplace_back(ri, i);
        else marks[i] = true;
        if(li != -1) sweep.emplace_back(li, -i);
        else marks[i] = true;
    }
    if(n > l){cout << "NIE\n"; return;}

    sort(all(sweep));

    int last = 0, free = 0;
    int opend = -1;
    bool flag = false;

    for(auto[x, y] : sweep){

        // cout << " - " << last << " " << x << '\n';
        // cout << free << '\n';

        if(last == x && opend != y){cout << "NIE\n"; return;}
        if(y > 0){

            if(opend == -1){

                // cout << "A " << x-last-1 << '\n';
                free += x - last - 1;
                // if(!flag && x-last-1) needToBeFree++;
                flag = false;
            } else{

                if(opend == y){

                    opend = -1;
                    last = x;
                    flag = false;
                    continue;
                }

                cout << "NIE\n";
                return;
            }
            last = x;
            continue;
        }

        if(opend != -1){

            cout << "NIE\n";
            return;
        }
        opend = -y;
        // cout << "B " << x-last-1 << '\n';

        free += x - last - 1;
        if(marks[-y]) {flag = true; opend = -1;}
        if(!flag && x-last-1) needToBeFree++;

        last = x;
    }

    free += l - last;
    if(!flag && l - last) needToBeFree ++;

    // cout << free << " == " << needToBeFree << '\n';

    if(needToBeFree > jokers || free < jokers){cout << "NIE\n"; return;}
    cout << "TAK\n";
}
int32_t main() { 
    sws;
    int t = 1;
    cin >> t;

    while(t--)
        solve();

return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 37ms
memory: 9600kb

input:

1
200000 1000000000
490669427 -1
224278942 224287156
821104480 -1
861696576 861702036
807438935 807440055
574078002 574083717
465630141 -1
195378188 -1
-1 13500961
-1 977536179
92893115 -1
-1 661145418
-1 215804863
-1 685338515
544348999 -1
465532902 -1
130346949 -1
-1 526666304
635604584 635605404
...

output:

TAK

result:

ok single line: 'TAK'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #4:

score: -100
Wrong Answer
time: 33ms
memory: 9600kb

input:

1
197838 400000
34167 34169
352180 -1
235963 -1
-1 -1
160401 160405
347288 -1
270353 270354
214502 214504
183243 183245
-1 -1
-1 36193
-1 -1
-1 17557
273498 273500
269137 -1
395099 395100
285515 285518
-1 -1
71041 71042
324060 -1
-1 385151
-1 379645
-1 -1
-1 185142
-1 191584
89259 89261
328347 32834...

output:

NIE

result:

wrong answer 1st lines differ - expected: 'TAK', found: 'NIE'