QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#412888 | #7514. Clique Challenge | Sorting | WA | 16ms | 44684kb | C++20 | 3.7kb | 2024-05-16 21:12:13 | 2024-05-16 21:12:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
const int MAXN = 1007 ;
const int LOG = 23 ;
const int MOD = 1e9 + 7 ;
int n , m ;
vector < int > v[ MAXN ] ;
int deg[ MAXN ] ;
pii srt[ MAXN ] ;
int ord[ MAXN ] ;
int adj[ MAXN ][ MAXN ] ;
int lval[ LOG ] , rval[ LOG ] ;
int hh[ ( 1 << LOG ) ] , dp[ ( 1 << LOG ) ] , val[ ( 1 << LOG ) ] ;
int lw[ ( 1 << LOG ) ] ;
void solve ( ) {
cin >> n >> m ;
for ( int i = 1 , x , y ; i <= m ; ++ i ) {
cin >> x >> y ;
adj[ x ][ y ] = adj[ y ][ x ] = 1 ;
v[ x ].push_back ( y ) ;
v[ y ].push_back ( x ) ;
++ deg[ x ] , ++ deg[ y ] ;
}
for ( int i = 1 ; i <= n ; ++ i ) {
srt[ i ] = { deg[ i ] , i } ;
}
sort ( srt + 1 , srt + n + 1 ) ;
for ( int i = 1 ; i <= n ; ++ i ) {
ord[ srt[ i ].se ] = i ;
}
for ( int i = 1 ; i < ( 1 << LOG ) ; ++ i ) {
while ( ( i & ( 1 << lw[ i ] ) ) == 0 ) { ++ lw[ i ] ; }
}
ll ans = 0 ;
for ( int x = 1 ; x <= n ; ++ x ) {
vector < int > aux[ 2 ] ;
int wh = 0 ;
for ( auto y : v[ x ] ) {
if ( ord[ x ] > ord[ y ] ) { continue ; }
aux[ wh ].push_back ( y ) ;
wh ^= 1 ;
}
int szl = aux[ 0 ].size ( ) ;
int szr = aux[ 1 ].size ( ) ;
for ( int i = 0 ; i < szr ; ++ i ) {
rval[ i ] = 0 ;
for ( int j = 0 ; j < szr ; ++ j ) {
if ( adj[ aux[ 1 ][ i ] ][ aux[ 1 ][ j ] ] == 1 ) {
rval[ i ] += ( 1 << j ) ;
}
}
}
for ( int i = 0 ; i < ( 1 << szr ) ; ++ i ) {
dp[ i ] = 0 ;
}
dp[ 0 ] = 1 ;
for ( int i = 1 ; i < ( 1 << szr ) ; ++ i ) {
int j = lw[ i ] , lft = i - ( 1 << lw[ i ] ) ;
if ( ( rval[ j ] & lft ) == lft && dp[ lft ] == 1 ) { dp[ i ] = 1 ; }
}
for ( int i = 0 ; i < szr ; ++ i ) {
for ( int j = 0 ; j < ( 1 << szr ) ; ++ j ) {
if ( ( j & ( 1 << i ) ) == 1 ) {
dp[ j ] = ( dp[ j ] + dp[ j ^ ( 1 << i ) ] ) % MOD ;
}
}
}
for ( int i = 0 ; i < szl ; ++ i ) {
rval[ i ] = 0 ;
for ( int j = 0 ; j < szr ; ++ j ) {
if ( adj[ aux[ 0 ][ i ] ][ aux[ 1 ][ j ] ] == 1 ) {
rval[ i ] += ( 1 << j ) ;
}
}
lval[ i ] = 0 ;
for ( int j = 0 ; j < szl ; ++ j ) {
if ( adj[ aux[ 0 ][ i ] ][ aux[ 0 ][ j ] ] == 1 ) {
lval[ i ] += ( 1 << j ) ;
}
}
}
for ( int i = 0 ; i < ( 1 << szl ) ; ++ i ) {
hh[ i ] = val[ i ] = 0 ;
}
hh[ 0 ] = 1 ;
val[ 0 ] = ( 1 << szr ) - 1 ;
for ( int i = 1 ; i < ( 1 << szl ) ; ++ i ) {
int j = lw[ i ] , lft = i - ( 1 << lw[ i ] ) ;
val[ i ] = ( val[ lft ] & rval[ j ] ) ;
if ( ( lval[ j ] & lft ) == lft && hh[ lft ] == 1 ) { hh[ i ] = 1 ; }
}
for ( int i = 0 ; i < ( 1 << szl ) ; ++ i ) {
if ( hh[ i ] == 1 ) {
ans = ( ans + dp[ val[ i ] ] ) % MOD ;
}
}
}
cout << ans << "\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: 16ms
memory: 42748kb
input:
3 2 1 2 2 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 4ms
memory: 42548kb
input:
3 3 1 2 1 3 2 3
output:
7
result:
ok single line: '7'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 44684kb
input:
1000 100 446 789 167 547 254 777 777 185 33 446 777 847 185 877 757 167 72 383 847 446 254 478 959 185 757 446 847 959 959 167 757 847 747 757 446 167 989 757 547 777 33 747 33 254 254 843 33 547 446 980 877 205 185 72 980 959 33 205 877 757 33 847 478 843 757 478 167 877 72 789 877 959 980 478 167 ...
output:
1145
result:
wrong answer 1st lines differ - expected: '1373', found: '1145'