QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408287 | #7178. Bishops | Sorting | RE | 1ms | 3656kb | C++20 | 1.7kb | 2024-05-09 23:12:56 | 2024-05-09 23:12:57 |
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 = 1e5 + 7 ;
int n , m ;
vector < pii > v ;
vector < pii > st[ MAXN ] ;
void f ( int par ) {
for ( int i = 0 ; i <= n + m ; ++ i ) { st[ i ].clear ( ) ; }
for ( int diff = n - 1 ; diff >= 1 - m ; -- diff ) {
if ( ( abs ( diff ) % 2 ) != par ) { continue ; }
int mnx = 1 + diff , mxx = m + diff ;
if ( mnx < 1 ) { mnx = 1 ; }
if ( mxx > n ) { mxx = n ; }
st[ mnx + ( mnx - diff ) ].push_back ( { mxx + ( mxx - diff ) , diff } ) ;
}
priority_queue < pii > q ;
for ( int i = 2 ; i <= n + m ; ++ i ) {
if ( ( i % 2 ) != par ) { continue ; }
for ( auto [ y , diff ] : st[ i ] ) { q.push ( { -y , diff } ) ; }
while ( q.empty ( ) == false ) {
auto [ x , diff ] = q.top ( ) ;
x = -x ;
q.pop ( ) ;
if ( x < i ) { continue ; }
int a = ( i + diff ) / 2 , b = i - a ;
v.push_back ( { a , b } ) ;
break ;
}
}
}
void solve ( ) {
cin >> n >> m ;
f ( 0 ) ;
f ( 1 ) ;
int sz = v.size ( ) ;
cout << sz << "\n" ;
for ( auto [ x , y ] : v ) {
cout << x << " " << y << "\n" ;
}
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
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: 1ms
memory: 3656kb
input:
2 5
output:
6 1 1 1 3 1 5 2 1 2 3 2 5
result:
ok n: 2, m: 5, bishops: 6
Test #2:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
5 5
output:
8 1 1 3 1 5 1 3 5 2 1 4 1 2 5 4 5
result:
ok n: 5, m: 5, bishops: 8
Test #3:
score: -100
Runtime Error
input:
100000 100000