Submission #493407

# Submission time Handle Problem Language Result Execution time Memory
493407 2021-12-11T08:27:07 Z khangal Nice sequence (IZhO18_sequence) C++14
30 / 100
113 ms 4976 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<long long> vl;
typedef pair<long long, long long > pl;
const int N = 1e6 + 1;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18 
#define MIN -1e18
#define per(i,a,b) for(ll i=b;i>=a;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
// typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// template< typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, m, ans, mid, mn, mx, cnt, sum, h1, h2, arr[3234567],arr1[1234567], sz, k, i, j, h, a, w, x, y, z,par[1234567];
bool used[1234567];
//ll dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},c1[123][123];
//vector<ll> edge[1234567];
//ll jump[22][223456];
//ll lvl[1234567];
//ll bit[1234567];
//ll timer;
//ll st[1234567],endd[1234567];
//ll dp[5005][5005];
ll power(ll base, ll val, ll mod) {
    ll res = 1;
    while (val) {
        if (val % 2 == 1) {
            res = res * base;
        }
        base = base * base;
        base %= mod;
        res %= mod;
        val /= 2;
    }
    return res;
}
bool comp(pl x,pl y){
    if(x.ff>y.ff)return true;
    return false;
}
ll find(ll x){
    if(x==par[x])return x;
    else return par[x]=find(par[x]);
}
pl findnum(ll x){
    ll res = x*x;
    ll l = n/x;
    l*=l;
    if(l%2==1){
        return {res*(l/2+1) , res*((l/2))};
    }
    else{
        return {res*(l/2) , res*((l/2))};        
    }
}
bool check(ll x,ll y,ll k){
    ll res = (x+k-1)/k + (y-1+k)/k;
    if(res%2==1)return false;
    else return true;
}
class A {
public:
    static void funcA() {
        cin>>n>>m;
        if((n==2 || m==2 )&& (max(n,m) % min(n,m) != 0 )){
            if(n==2){
                cout<<m<<'\n';
                ll l = 1e5;
                for(int i=1;i<=max(m,n);i++){
                    if(i%2==1)cout<<(l)<<" ";
                    else cout<<-(l+1)<<" ";
                }
                cout<<'\n';
            }
            else{
                cout<<n<<'\n';
                ll l = 1e5;
                for(int i=1;i<=max(m,n);i++){
                    if(i%2==1)
                    cout<<-(l)<<" ";
                    else cout<<l+1<<" ";
                }
                cout<<'\n';
            }
            return;
        }
        if(max(n,m) % min(n,m) == 0){
            cout<<max(n,m)-1<<'\n';
            if(n>m){
                for(int i=1;i<max(m,n);i++)cout<<1<<" ";
            }
            else for(int i=1;i<max(n,m);i++)cout<<-1<<' ';
            cout<<'\n';
            return;
        }
        if(abs(n-m)<=2){
            if(n==m+2 && n%2==1){
                cout<<2*m<<'\n';
                for(int i=1;i<m;i+=2)cout<<m<<" "<<-n<<' ';
                cout<<m<<" "<<m<<" ";
                for(int i=1;i<m;i+=2)cout<<-n<<" "<<m<<' ';
                cout<<'\n';
                return;
            }
            if(n>m){
                cout<<2*m-1<<'\n';
                for(int i=1;i<m;i++)cout<<-2<<" ";
                cout<<2*m-1<<" ";
                for(int i=1;i<m;i++)cout<<-2<<" ";
                cout<<'\n';
                return;
            }
            if(m==n+2 && n%2==1){
                cout<<2*n<<'\n';
                for(int i=1;i<n;i+=2)cout<<-n<<" "<<m<<' ';
                cout<<-n<<" "<<-n<<" ";
                for(int i=1;i<n;i+=2)cout<<m<<" "<<-n<<' ';
                cout<<'\n';
                return;
            }
            if(m>n){
                cout<<2*n-1<<'\n';
                for(int i=1;i<n;i++)cout<<2<<" ";
                cout<<-(2*n-1)<<" ";
                for(int i=1;i<n;i++)cout<<2<<" ";
                cout<<'\n';
                return;
            }
        }
    }
}lol;
void solve() {
    A::funcA();
}
int main() {
    ll T = 1;
    cin>>T;
    boost;
    while (T--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 2 ms 332 KB Ok
7 Correct 8 ms 716 KB Ok
8 Correct 4 ms 460 KB Ok
9 Correct 10 ms 716 KB Ok
10 Correct 6 ms 480 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Incorrect 0 ms 204 KB Jury has the better answer : jans = 9, pans = 2
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 66 ms 3016 KB Ok
7 Correct 53 ms 2372 KB Ok
8 Correct 113 ms 4564 KB Ok
9 Correct 91 ms 4976 KB Ok
10 Correct 48 ms 1800 KB Ok
11 Correct 103 ms 3888 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Incorrect 0 ms 204 KB Jury has the better answer : jans = 9, pans = 2
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Correct 0 ms 204 KB Ok
17 Correct 0 ms 204 KB Ok
18 Correct 2 ms 332 KB Ok
19 Correct 8 ms 716 KB Ok
20 Correct 4 ms 460 KB Ok
21 Correct 10 ms 716 KB Ok
22 Correct 6 ms 480 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 0 ms 204 KB Ok
26 Incorrect 0 ms 204 KB Jury has the better answer : jans = 9, pans = 2
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 1 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 0 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Correct 0 ms 204 KB Ok
17 Correct 0 ms 204 KB Ok
18 Correct 2 ms 332 KB Ok
19 Correct 8 ms 716 KB Ok
20 Correct 4 ms 460 KB Ok
21 Correct 10 ms 716 KB Ok
22 Correct 6 ms 480 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 0 ms 204 KB Ok
26 Incorrect 0 ms 204 KB Jury has the better answer : jans = 9, pans = 2
27 Halted 0 ms 0 KB -