QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693358#6705. MedianKdlyh#AC ✓12ms3620kbC++203.6kb2024-10-31 16:00:582024-10-31 16:01:00

Judging History

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

  • [2024-10-31 16:01:00]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:3620kb
  • [2024-10-31 16:00:58]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <stack>

#ifdef LOCAL
template <class T, size_t size = std::tuple_size<T>::value> std::string to_debug(T, std::string s = "") requires(not std::ranges::range<T>);
std::string to_debug(auto x) requires requires(std::ostream& os) { os << x; } { return static_cast<std::ostringstream>(std::ostringstream() << x).str(); }
std::string to_debug(std::ranges::range auto x, std::string s = "") requires(not std::is_same_v<decltype(x), std::string>) {
  for (auto xi : x) { s += ", " + to_debug(xi); }
  return "[" + s.substr(s.empty() ? 0 : 2) + "]";
}
template <class T, size_t size> std::string to_debug(T x, std::string s) requires(not std::ranges::range<T>) {
  [&]<size_t... I>(std::index_sequence<I...>) { ((s += ", " + to_debug(get<I>(x))), ...); }(std::make_index_sequence<size>());
  return "(" + s.substr(s.empty() ? 0 : 2) + ")";
}
#define debug(...) std::cerr << __LINE__ << ": (" #__VA_ARGS__ ") = " << to_debug(std::tuple(__VA_ARGS__)) << "\n"
#else
#define debug(x...)
#endif

using i64 = long long;
using namespace std;
void solve()
{
#define tests
    int n, m;
    std::cin >> n >> m;
    std::vector e(n + 10, std::vector<int>(n + 10));
    const int inf = 1e9+7;
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= n ; j++){
            e[i][j] = inf;
        }
        e[i][i] = 0;
    }
    bool ok{true};
    for(int i = 1 ; i <= m ; i++){
        int a, b;
        std::cin >> a >> b;
        if(a==b){
            ok = false;
        }
        e[b][a] = 1;
    }
    if(!ok){
        for(int i = 1 ; i <= n ; i++)
            std::cout << '0';
        std::cout <<'\n';
        return;
    }

    for(int k = 1 ; k <= n ; k++){
        for(int i = 1 ; i <= n ; i++){
            for(int j = 1 ; j <= n ; j++){
                e[i][j] = std::min(e[i][j], e[i][k] + e[k][j]);
            }
        }
    }

    vector<int>ans;
    for(int i = 1 ; i <= n ; i++){
        int maxx{}, minn{};
        set<int>res1;
        //bool okk=true;
        for(int j = 1 ; j <= n ; j++){
            if(e[i][j] != inf and e[i][j]>0){
                maxx ++;
                res1.insert(j);
            }
        }
        for(int j=1;j<=n;j++){
            if(e[j][i] != inf and e[j][i]>0){
                minn ++;
                if(res1.contains(j)){
                    ok=false;
                    break;
                }
            }
        }
        if(!ok){
            break;
        }
        //std::cerr <<i<<":"<< maxx <<" "<<minn<< "\n";
        if(maxx > n / 2 or minn > n / 2){
            //std::cout << '0';
            ans.push_back(0);
        }else{
            //std::cout << '1';
            ans.push_back(1);
        }
    }
    if(!ok){
        for(int i=1;i<=n;i++){
            cout<<"0";
        }
        cout<<"\n";
        return;
    }
    else{
        for(auto e:ans){
            cout<<e;
        }
        cout<<"\n";
    }
    //std::cout << '\n';
}
 
signed main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int _{1};
#ifdef tests
    std::cin >> _;
#endif
    while(_--) solve();
    return 0;
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5 4
1 2
3 2
2 4
2 5
3 2
1 1
2 3

output:

01000
000

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 12ms
memory: 3620kb

input:

66
13 2
9 13
7 11
11 19
9 1
8 1
5 1
2 8
4 2
2 1
5 2
6 3
3 11
3 2
4 6
6 10
9 8
3 5
1 7
5 8
3 9
4 9
6 7
3 1
2 3
11 6
9 4
1 6
5 2
1 5
4 6
8 4
15 15
10 6
15 8
7 6
11 1
5 2
3 4
11 13
4 6
10 12
10 13
1 6
15 2
5 12
13 14
5 3
15 86
14 12
8 1
14 9
8 15
5 10
1 9
11 2
6 2
7 10
10 13
14 5
4 13
5 8
4 10
13 9
6 9...

output:

1111111111111
01001000111
111
11111111111
111111111111111
001001000000000
00100
01100
1111111
1000000000000
111101101
111111111
000011111011101
010111111
001100000
0100001001101
1111111111111
001000010000000
10010111011
001000000000100
11111111111
00100000011
11111
01000000110
11101110111
00000
1111...

result:

ok 66 lines