QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#173773 | #7178. Bishops | ucup-team180# | WA | 18ms | 9408kb | C++23 | 7.0kb | 2023-09-10 01:53:55 | 2023-09-10 01:53:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using ull = unsigned long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
template<class T> using pqmin = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pqmax = priority_queue<T>;
const ll inf=LLONG_MAX/3;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define si(x) ll(x.size())
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rng(i,l,r) for(ll i=l;i<r;i++)
#define gnr(i,l,r) for(ll i=r-1;i>=l;i--)
#define fore(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
template<class T> bool chmin(T& a, const T& b){ if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, const T& b){ if(a >= b) return 0; a = b; return 1; }
template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); }
template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); }
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define VLL(name,size) vector<ll>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>> name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>> name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>> name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SUM(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
template<class T, class F = less<>> void sor(T& a, F b = F{}){ sort(all(a), b); }
template<class T> void uniq(T& a){ sor(a); a.erase(unique(all(a)), end(a)); }
void outb(bool x){cout<<(x?"Yes":"No")<<"\n";}
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
ll gcd(ll a,ll b){return (b?gcd(b,a%b):a);}
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); per(i,ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
vll prime_table(ll n){vec(ll,isp,n+1,1);vll res;rng(i,2,n+1)if(isp[i]){res.pb(i);for(ll j=i*i;j<=n;j+=i)isp[j]=0;}return res;}
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }
template <class T> vector<T> &operator++(vector<T> &v) {
fore(e, v) e++;
return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
auto res = v;
fore(e, v) e++;
return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
fore(e, v) e--;
return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
auto res = v;
fore(e, v) e--;
return res;
}
template <class T> vector<T> &operator+=(vector<T> &l, const vector<T> &r) {
fore(e, r) l.eb(e);
return l;
}
template<class... Ts> void in(Ts&... t);
[[maybe_unused]] void print(){}
template<class T, class... Ts> void print(const T& t, const Ts&... ts);
template<class... Ts> void out(const Ts&... ts){ print(ts...); cout << '\n'; }
namespace IO{
#define VOID(a) decltype(void(a))
struct S{ S(){ cin.tie(nullptr)->sync_with_stdio(0); fixed(cout).precision(12); } }S;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...); }
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{}); }
template<class T> void o(const T& t){ o(t, P<4>{}); }
template<size_t N> void o(const char (&t)[N], P<4>){ cout << t; }
template<class T, size_t N> void o(const T (&t)[N], P<3>){ o(t[0]); for(size_t i = 1; i < N; i++){ o(' '); o(t[i]); } }
template<class T> auto o(const T& t, P<2>) -> VOID(cout << t){ cout << t; }
template<class T> auto o(const T& t, P<1>) -> VOID(begin(t)){ bool first = 1; for(auto&& x : t) { if(first) first = 0; else o(' '); o(x); } }
template<class T, size_t... idx> void otuple(const T& t, index_sequence<idx...>){ print(get<idx>(t)...); }
template<class T> auto o(T& t, P<0>) -> VOID(tuple_size<T>{}){ otuple(t, make_index_sequence<tuple_size<T>::value>{}); }
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO::i(t)); }
template<class T, class... Ts> void print(const T& t, const Ts&... ts){ IO::o(t); unpack(IO::o((cout << ' ', ts))); }
#undef unpack
void solve(ll n,ll m,vpll &res){
if(n==1&&m==1){
res.eb(0,0);
return;
}
if(n==m){
rep(i,n-1){
res.eb(0,i);
res.eb(n-1,i);
}
return;
}
bool swapped=0;
if(n>m){
swapped=1;
swap(n,m);
}
ll r=m%n;
if(r==0)r=n;
solve(n,r,res);
rep(k,(m-r)/n){
rep(i,n)res.eb(r+k*n+n-1,i);
}
if(swapped){
swap(n,m);
fore2(x,y,res)swap(x,y);
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
LL(n,m);
vpll ans;
solve(n,m,ans);
out(si(ans));
fore2(x,y,ans){
cout<<y+1<<" "<<x+1<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3868kb
input:
2 5
output:
6 1 1 2 1 1 3 2 3 1 5 2 5
result:
ok n: 2, m: 5, bishops: 6
Test #2:
score: 0
Accepted
time: 2ms
memory: 3640kb
input:
5 5
output:
8 1 1 1 5 2 1 2 5 3 1 3 5 4 1 4 5
result:
ok n: 5, m: 5, bishops: 8
Test #3:
score: 0
Accepted
time: 16ms
memory: 9148kb
input:
100000 100000
output:
199998 1 1 1 100000 2 1 2 100000 3 1 3 100000 4 1 4 100000 5 1 5 100000 6 1 6 100000 7 1 7 100000 8 1 8 100000 9 1 9 100000 10 1 10 100000 11 1 11 100000 12 1 12 100000 13 1 13 100000 14 1 14 100000 15 1 15 100000 16 1 16 100000 17 1 17 100000 18 1 18 100000 19 1 19 100000 20 1 20 100000 21 1 21 100...
result:
ok n: 100000, m: 100000, bishops: 199998
Test #4:
score: 0
Accepted
time: 18ms
memory: 9396kb
input:
100000 99999
output:
199998 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 ...
result:
ok n: 100000, m: 99999, bishops: 199998
Test #5:
score: 0
Accepted
time: 18ms
memory: 9408kb
input:
100000 50000
output:
149998 1 1 50000 1 1 2 50000 2 1 3 50000 3 1 4 50000 4 1 5 50000 5 1 6 50000 6 1 7 50000 7 1 8 50000 8 1 9 50000 9 1 10 50000 10 1 11 50000 11 1 12 50000 12 1 13 50000 13 1 14 50000 14 1 15 50000 15 1 16 50000 16 1 17 50000 17 1 18 50000 18 1 19 50000 19 1 20 50000 20 1 21 50000 21 1 22 50000 22 1 2...
result:
ok n: 100000, m: 50000, bishops: 149998
Test #6:
score: 0
Accepted
time: 11ms
memory: 5220kb
input:
1 100000
output:
100000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 ...
result:
ok n: 1, m: 100000, bishops: 100000
Test #7:
score: 0
Accepted
time: 17ms
memory: 7720kb
input:
34535 99889
output:
134423 1 1 1 2 3 1 3 2 5 1 5 2 1 7 2 7 3 7 4 7 5 7 12 1 12 2 12 3 12 4 12 5 12 6 12 7 19 1 19 2 19 3 19 4 19 5 19 6 19 7 26 1 26 2 26 3 26 4 26 5 26 6 26 7 33 1 33 2 33 3 33 4 33 5 33 6 33 7 1 40 2 40 3 40 4 40 5 40 6 40 7 40 8 40 9 40 10 40 11 40 12 40 13 40 14 40 15 40 16 40 17 40 18 40 19 40 20 4...
result:
ok n: 34535, m: 99889, bishops: 134423
Test #8:
score: 0
Accepted
time: 8ms
memory: 5276kb
input:
12231 97889
output:
110119 1 1 1 2 3 1 3 2 5 1 5 2 7 1 7 2 9 1 9 2 11 1 11 2 13 1 13 2 1 15 2 15 3 15 4 15 5 15 6 15 7 15 8 15 9 15 10 15 11 15 12 15 13 15 1 28 2 28 3 28 4 28 5 28 6 28 7 28 8 28 9 28 10 28 11 28 12 28 13 28 1 41 2 41 3 41 4 41 5 41 6 41 7 41 8 41 9 41 10 41 11 41 12 41 13 41 54 1 54 2 54 3 54 4 54 5 5...
result:
ok n: 12231, m: 97889, bishops: 110119
Test #9:
score: 0
Accepted
time: 7ms
memory: 5264kb
input:
10000 100000
output:
109998 1 1 1 10000 2 1 2 10000 3 1 3 10000 4 1 4 10000 5 1 5 10000 6 1 6 10000 7 1 7 10000 8 1 8 10000 9 1 9 10000 10 1 10 10000 11 1 11 10000 12 1 12 10000 13 1 13 10000 14 1 14 10000 15 1 15 10000 16 1 16 10000 17 1 17 10000 18 1 18 10000 19 1 19 10000 20 1 20 10000 21 1 21 10000 22 1 22 10000 23 ...
result:
ok n: 10000, m: 100000, bishops: 109998
Test #10:
score: 0
Accepted
time: 3ms
memory: 5348kb
input:
13 99999
output:
100011 1 1 1 2 1 3 4 1 4 2 4 3 7 1 7 2 7 3 10 1 10 2 10 3 13 1 13 2 13 3 1 16 2 16 3 16 4 16 5 16 6 16 7 16 8 16 9 16 10 16 11 16 12 16 13 16 1 29 2 29 3 29 4 29 5 29 6 29 7 29 8 29 9 29 10 29 11 29 12 29 13 29 1 42 2 42 3 42 4 42 5 42 6 42 7 42 8 42 9 42 10 42 11 42 12 42 13 42 1 55 2 55 3 55 4 55 ...
result:
ok n: 13, m: 99999, bishops: 100011
Test #11:
score: -100
Wrong Answer
time: 7ms
memory: 5400kb
input:
21 99999
output:
100018 1 1 1 3 2 1 2 3 1 6 2 6 3 6 1 9 2 9 3 9 1 12 2 12 3 12 1 15 2 15 3 15 1 18 2 18 3 18 21 1 21 2 21 3 21 4 21 5 21 6 21 7 21 8 21 9 21 10 21 11 21 12 21 13 21 14 21 15 21 16 21 17 21 18 1 39 2 39 3 39 4 39 5 39 6 39 7 39 8 39 9 39 10 39 11 39 12 39 13 39 14 39 15 39 16 39 17 39 18 39 19 39 20 3...
result:
wrong answer Participant's answer is not optimal (100018 < 100019)