QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795006#9799. Magical Paletteucup-team5234#TL 0ms3624kbC++203.6kb2024-11-30 17:25:202024-11-30 17:25:28

Judging History

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

  • [2024-11-30 17:25:28]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3624kb
  • [2024-11-30 17:25:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using VVVV = VV<VV<T>>;
#define rep(i,n) for(ll i=0ll;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
const long long INF = (1LL << 60);
const long long mod99 = 998244353;
const long long mod107 = 1000000007;
const long long mod = mod99;
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
#define all(i,v) for(auto& i : v)
#define UQ(v) sort(be(v)), v.erase(unique(be(v)), v.end())
#define LB(x,v) (lower_bound(be(v),(x))-(v).begin())
#define UB(x,v) (upper_bound(be(v),(x))-(v).begin())
#define dout()  cout << fixed << setprecision(20)
#define randinit() srand((unsigned)time(NULL))

template<class T, class U> bool chmin(T& t, const U& u) { if (t > u){ t = u; return 1;} return 0; }
template<class T, class U> bool chmax(T& t, const U& u) { if (t < u){ t = u; return 1;} return 0; }




void solve(){
    ll n,m;
    cin >> n >> m;
    {
        VV<ll> v(n, V<ll>(m, 0));
        V<ll> a(n), b(m);
        a[0] = n;
        b[0] = m;
        REP(i, 1, n){
            a[i] = i;
            while(a[i]%(n*m) == n%(n*m) || a[i]%(n*m) == m%(n*m)) a[i] += n;
            a[i] %= (n*m);
        }
        REP(i, 1, m){
            b[i] = 1 + (i-1)*n;
            while(b[i]%(n*m) == n%(n*m) || b[i]%(n*m) == m%(n*m)) b[i] += m;
            b[i] %= (n*m);
        }
        V<ll> cnt(n*m, 0);
        ll f = 1;
        rep(i, n) rep(j, m){
            v[i][j] = a[i]*b[j]%(n*m);
            cnt[v[i][j]] ++;
            if(cnt[v[i][j]] > 1) f = 0;
        }
        if(f){
            cout << "Yes" << endl;
            for(auto x:a) cout << x%(n*m) << " ";
            cout << endl;
            for(auto x:b) cout << x%(n*m) << " ";
            cout << endl;
            return;
        }
    }

    {
        swap(n, m);
        VV<ll> v(n, V<ll>(m, 0));
        V<ll> a(n), b(m);
        a[0] = n;
        b[0] = m;
        REP(i, 1, n){
            a[i] = i;
            while(a[i]%(n*m) == n%(n*m) || a[i]%(n*m) == m%(n*m)) a[i] += n;
            a[i] %= (n*m);
        }
        REP(i, 1, m){
            b[i] = 1 + (i-1)*n;
            while(b[i]%(n*m) == n%(n*m) || b[i]%(n*m) == m%(n*m)) b[i] += m;
            b[i] %= (n*m);
        }
        V<ll> cnt(n*m, 0);
        ll f = 1;
        rep(i, n) rep(j, m){
            v[i][j] = a[i]*b[j]%(n*m);
            cnt[v[i][j]] ++;
            if(cnt[v[i][j]] > 1) f = 0;
        }
        swap(a, b);
        if(f){
            cout << "Yes" << endl;
            for(auto x:a) cout << x%(n*m) << " ";
            cout << endl;
            for(auto x:b) cout << x%(n*m) << " ";
            cout << endl;
            return;
        }
    }ll sw = 0;
    if(n > m){
        swap(n, m);
        sw = 1;
    }
    VV<ll> v(n, V<ll>(m, 0));
    V<ll> a(n), b(m);
    rep(i, n) a[i] = (i+1)%(n*m);
    rep(i, m) b[i] = (1 + i*n)%(n*m);
    V<ll> cnt(n*m, 0);
    rep(i, n) rep(j, m){
        v[i][j] = a[i]*b[j]%(n*m);
        cnt[v[i][j]] ++;
        if(cnt[v[i][j]] > 1){
            cout << "No" << endl;
            return;
        }
    }
    if(sw){
        swap(n, m);
        swap(a, b);
    }
    cout << "Yes" << endl;
    for(auto x:a) cout << x << " ";
    cout << endl;
    for(auto x:b) cout << x << " ";
    cout << endl;
}





int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t=1;
    cin >> t;
    rep(i,t) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
2 3
2 2

output:

Yes
2 1 
3 1 5 
No

result:

ok 2 cases (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

1
1 1000000

output:


result: