QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56063 | #4883. Bayan Testing | Sorting# | WA | 43ms | 16144kb | C++ | 1.7kb | 2022-10-16 19:13:09 | 2022-10-16 19:13:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MAXN = 5e5 + 7 ;
int n , m ;
pii a[ MAXN ] ;
vector < int > v[ MAXN ] ;
int wh[ MAXN ] ;
int ans[ MAXN ] ;
void solve ( ) {
cin >> n >> m ;
int mx = 0 ;
for ( int i = 1 ; i <= 2 * m ; ++ i ) {
cin >> a[ i ].fi >> a[ i ].se ;
if ( a[ i ].fi != a[ i ].se ) { ++ mx ; }
}
if ( mx < m ) {
cout << "-1\n" ;
return ;
}
for ( int i = 1 ; i <= n ; ++ i ) {
v[ i ].clear ( ) ;
wh[ i ] = 0 ;
ans[ i ] = 0 ;
}
for ( int i = 1 ; i <= 2 * m ; ++ i ) {
if ( a[ i ].fi == a[ i ].se ) { continue ; }
v[ a[ i ].se ].push_back ( a[ i ].fi ) ;
}
for ( int i = 1 ; i <= n ; ++ i ) {
sort ( v[ i ].begin ( ) , v[ i ].end ( ) ) ;
}
int k = m ;
for ( int i = n ; i >= 1 ; -- i ) {
int sz = v[ i ].size ( ) ;
if ( sz == 0 ) { continue ; }
if ( k >= sz ) {
k -= sz ;
wh[ i ] = v[ i ].back ( ) ;
}
else {
if ( k > 0 ) {
wh[ i ] = v[ i ][ k ] ;
k = 0 ;
}
}
}
for ( int i = 1 ; i <= n ; ++ i ) {
if ( wh[ i ] == 0 ) { ans[ i ] = i ; }
else { ans[ i ] = ans[ wh[ i ] ] ; }
}
for ( int i = 1 ; i <= n ; ++ i ) {
cout << ans[ i ] << " " ;
}
cout << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 16136kb
input:
3 2 1 1 1 2 2 6 2 1 3 4 6 2 4 3 5 4 3 1 2 1 1 2 2 2 3 3 3 3 4
output:
-1 1 2 3 4 3 4 1 1 1 1
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 37ms
memory: 15932kb
input:
100000 2 1 1 1 2 2 2 1 2 2 1 2 2 1 1 2 2 2 2 1 1 2 2 2 2 1 2 2 1 2 2 1 2 2 1 1 2 1 1 1 2 2 2 1 1 2 2 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2 1 1 1 2 2 2 1 2 2 1 2 2 1 2...
output:
-1 1 1 1 1 1 1 1 1 -1 -1 1 1 -1 1 1 -1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 1 1 -1 -1 1 1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 -1 -1 1 ...
result:
ok ok (100000 test cases)
Test #3:
score: -100
Wrong Answer
time: 43ms
memory: 16144kb
input:
25000 10 5 4 10 1 4 9 9 2 9 5 8 1 8 1 5 5 5 4 9 6 6 11 5 9 11 4 7 2 2 2 5 8 10 3 11 2 4 4 8 3 10 4 6 5 2 1 3 4 4 1 5 5 5 6 3 4 6 3 3 1 5 3 6 1 1 1 3 7 3 4 4 3 5 1 6 3 4 2 3 1 2 7 3 3 4 1 5 6 7 2 6 3 5 2 3 5 2 5 5 4 5 2 3 1 1 10 5 3 6 4 5 3 3 6 9 2 5 9 10 5 6 5 7 1 4 8 9 11 5 1 10 2 11 6 9 2 6 6 6 8 ...
output:
1 2 3 4 5 6 7 5 4 4 1 2 3 4 5 6 7 4 9 4 9 1 2 1 4 1 1 2 3 4 1 4 1 2 3 3 3 1 7 1 2 3 4 3 2 2 1 2 2 4 4 1 2 3 4 5 5 5 8 8 8 1 2 3 4 5 6 7 8 9 1 9 1 2 3 4 5 4 4 4 1 2 3 4 5 6 7 4 9 9 1 2 3 4 5 2 4 8 1 2 3 4 5 6 7 8 8 10 11 8 8 14 6 3 14 1 2 3 4 5 6 7 8 9 8 5 8 2 1 2 3 4 1 4 1 2 3 4 5 6 6...
result:
wrong answer the number of segments with two equal elements is 4 != 3 (test case 6)