1733B - Rule of League - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, x, y = map(int, input().split())
    if (bool(x) ^ bool(y)) and not ((n-1) % max(x, y)):
        x = max(x, y)
        ans = [1]*x
        for i in range(x, n-1, x):
            ans += [i+2]*x
        print(*ans)
    else:
        print('-1')

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 33
int main(){
  int test;cin>>test;
  while(test--){
    int n,s,k;cin>>n>>s>>k;
    if(s!=0&&k!=0){
      cout<<-1<<endl;
      continue;
    }
    if(s==0&&k==0){
      cout<<-1<<endl;
      continue;
    }
    if(s>k)swap(s,k);
    if((n-1)%k){
      cout<<-1<<endl;
      continue;
    }
    for(int i=2;i<=n;i+=k){
      for(int j=0;j<k;j++)cout<<i<<" ";
      
    }cout<<endl;
  }
}


Comments

Submit
0 Comments
More Questions

Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!