提出 #61638866
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#ifdef LOCAL
#include <print.h>
#else
#define trace(...)
#define endl '\n' // remove in interactive
#endif
void solve(){
int n, m;
cin >> n >> m;
vector<int> l(m), r(m), perm(m);
int one = -1;
int ml = -1, MR = -1;
for(int i = 0; i < m; i++){
cin >> l[i] >> r[i];
perm[i] = i;
if(l[i]==1 && r[i] == n) one = i;
if(l[i] == 1){
if(MR == -1 || r[MR] < r[i]) MR = i;
}
if(r[i] == n){
if(ml == -1 || l[ml] > l[i]) ml = i;
}
}
if(one != -1){
cout << 1 << endl;
for(int i = 0; i < m; i++) cout << (i == one ? 1 : 0) << " ";
cout << endl;
return;
}
sort(all(perm), [&](int i, int j){return l[i] < l[j] || (l[i] == l[j] && r[i] > r[j]);});
int max_l = perm[0], min_r = perm[0];
for(int i = 1; i < m; i++){
int x = perm[i], y = perm[i - 1];
if(l[x] > l[max_l]) max_l = x;
if(r[x] < r[min_r]) min_r = x;
if(r[x] <= r[y]){
cout << 2 << endl;
for(int j = 0; j < m; j++){
int v = 0;
if(j == x) v = 2;
if(j == y) v = 1;
cout << v << " ";
}
cout << endl;
return;
}
}
if(l[max_l] > r[min_r]){
cout << 2 << endl;
for(int i = 0; i < m;i++){
cout << ((i == max_l || i == min_r) ? 2 : 0) << " ";
}
cout << endl;
return;
}
if(ml != -1 && MR != -1 && l[ml] <= r[MR]){
cout << 2 << endl;
for(int i = 0; i < m; i++){
cout << ((i == ml || i == MR) ? 1 : 0) << " ";
}
cout << endl;
return;
}
if(m <= 2){
cout << -1 << endl;
return;
}
cout << 3 << endl;
int done = 0;
for(int i = 0; i < m; i++){
int v = 0;
if(i == max_l || i == min_r) v = 2;
if(!done && !v) v = done = 1;
cout << v << " ";
}
cout << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); // Remove in interactive problems
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | A - Inside or Outside |
| ユーザ | jtnydv25 |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 700 |
| コード長 | 2009 Byte |
| 結果 | AC |
| 実行時間 | 44 ms |
| メモリ | 5516 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 700 / 700 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt |
| All | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 02_small_15.txt, 02_small_16.txt, 02_small_17.txt, 03_max_rand_1_01.txt, 03_max_rand_1_02.txt, 03_max_rand_1_03.txt, 03_max_rand_1_04.txt, 03_max_rand_1_05.txt, 04_max_rand_2_01.txt, 04_max_rand_2_02.txt, 04_max_rand_2_03.txt, 04_max_rand_2_04.txt, 04_max_rand_2_05.txt, 05_one_01.txt, 05_one_02.txt, 06_three_01.txt, 06_three_02.txt, 06_three_03.txt, 06_three_04.txt, 06_three_05.txt, 06_three_06.txt, 06_three_07.txt, 06_three_08.txt, 06_three_09.txt, 06_three_10.txt, 07_two_01.txt, 07_two_02.txt, 07_two_03.txt, 07_two_04.txt, 07_two_05.txt, 07_two_06.txt, 07_two_07.txt, 07_two_08.txt, 07_two_09.txt, 07_two_10.txt, 07_two_11.txt, 07_two_12.txt, 07_two_13.txt, 07_two_14.txt, 07_two_15.txt, 07_two_16.txt, 07_two_17.txt, 07_two_18.txt, 07_two_19.txt, 08_special_01.txt, 08_special_02.txt, 08_special_03.txt, 08_special_04.txt, 08_special_05.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01_sample_01.txt | AC | 1 ms | 3604 KiB |
| 01_sample_02.txt | AC | 1 ms | 3460 KiB |
| 01_sample_03.txt | AC | 1 ms | 3604 KiB |
| 01_sample_04.txt | AC | 1 ms | 3420 KiB |
| 02_small_01.txt | AC | 1 ms | 3452 KiB |
| 02_small_02.txt | AC | 1 ms | 3412 KiB |
| 02_small_03.txt | AC | 1 ms | 3440 KiB |
| 02_small_04.txt | AC | 1 ms | 3400 KiB |
| 02_small_05.txt | AC | 1 ms | 3416 KiB |
| 02_small_06.txt | AC | 1 ms | 3420 KiB |
| 02_small_07.txt | AC | 1 ms | 3412 KiB |
| 02_small_08.txt | AC | 1 ms | 3432 KiB |
| 02_small_09.txt | AC | 1 ms | 3604 KiB |
| 02_small_10.txt | AC | 1 ms | 3420 KiB |
| 02_small_11.txt | AC | 1 ms | 3452 KiB |
| 02_small_12.txt | AC | 1 ms | 3468 KiB |
| 02_small_13.txt | AC | 1 ms | 3488 KiB |
| 02_small_14.txt | AC | 1 ms | 3452 KiB |
| 02_small_15.txt | AC | 1 ms | 3544 KiB |
| 02_small_16.txt | AC | 1 ms | 3508 KiB |
| 02_small_17.txt | AC | 3 ms | 3604 KiB |
| 03_max_rand_1_01.txt | AC | 42 ms | 5460 KiB |
| 03_max_rand_1_02.txt | AC | 43 ms | 5380 KiB |
| 03_max_rand_1_03.txt | AC | 44 ms | 5412 KiB |
| 03_max_rand_1_04.txt | AC | 43 ms | 5356 KiB |
| 03_max_rand_1_05.txt | AC | 43 ms | 5288 KiB |
| 04_max_rand_2_01.txt | AC | 42 ms | 5408 KiB |
| 04_max_rand_2_02.txt | AC | 43 ms | 5364 KiB |
| 04_max_rand_2_03.txt | AC | 42 ms | 5376 KiB |
| 04_max_rand_2_04.txt | AC | 42 ms | 5376 KiB |
| 04_max_rand_2_05.txt | AC | 42 ms | 5380 KiB |
| 05_one_01.txt | AC | 24 ms | 5196 KiB |
| 05_one_02.txt | AC | 14 ms | 4300 KiB |
| 06_three_01.txt | AC | 34 ms | 4880 KiB |
| 06_three_02.txt | AC | 41 ms | 5428 KiB |
| 06_three_03.txt | AC | 41 ms | 5368 KiB |
| 06_three_04.txt | AC | 11 ms | 3632 KiB |
| 06_three_05.txt | AC | 39 ms | 5120 KiB |
| 06_three_06.txt | AC | 22 ms | 4352 KiB |
| 06_three_07.txt | AC | 27 ms | 4628 KiB |
| 06_three_08.txt | AC | 4 ms | 3552 KiB |
| 06_three_09.txt | AC | 41 ms | 5428 KiB |
| 06_three_10.txt | AC | 32 ms | 4884 KiB |
| 07_two_01.txt | AC | 44 ms | 5320 KiB |
| 07_two_02.txt | AC | 44 ms | 5412 KiB |
| 07_two_03.txt | AC | 44 ms | 5392 KiB |
| 07_two_04.txt | AC | 43 ms | 5364 KiB |
| 07_two_05.txt | AC | 44 ms | 5360 KiB |
| 07_two_06.txt | AC | 43 ms | 5416 KiB |
| 07_two_07.txt | AC | 44 ms | 5424 KiB |
| 07_two_08.txt | AC | 43 ms | 5472 KiB |
| 07_two_09.txt | AC | 43 ms | 5376 KiB |
| 07_two_10.txt | AC | 43 ms | 5380 KiB |
| 07_two_11.txt | AC | 44 ms | 5368 KiB |
| 07_two_12.txt | AC | 43 ms | 5360 KiB |
| 07_two_13.txt | AC | 43 ms | 5388 KiB |
| 07_two_14.txt | AC | 43 ms | 5428 KiB |
| 07_two_15.txt | AC | 43 ms | 5364 KiB |
| 07_two_16.txt | AC | 44 ms | 5372 KiB |
| 07_two_17.txt | AC | 43 ms | 5388 KiB |
| 07_two_18.txt | AC | 43 ms | 5360 KiB |
| 07_two_19.txt | AC | 43 ms | 5284 KiB |
| 08_special_01.txt | AC | 29 ms | 5516 KiB |
| 08_special_02.txt | AC | 28 ms | 5448 KiB |
| 08_special_03.txt | AC | 1 ms | 3448 KiB |
| 08_special_04.txt | AC | 1 ms | 3444 KiB |
| 08_special_05.txt | AC | 1 ms | 3416 KiB |