1430A - Number of Apartments - CodeForces Solution


brute force constructive algorithms math *900

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    if n in [1, 2, 4]:
        print(-1)
    else:
        if n % 3 == 0:
            print(n//3, 0, 0)
        elif n % 3 == 1:
            print((n-7)//3, 0, 1)
        else:
            print((n-5)//3, 1, 0)

C++ Code:

#include <bits/stdc++.h>
#include <deque>
#include<algorithm>
using namespace std;
using ll = long long;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define vi vector< int >
#define vl vector< ll >
#define mi map<int ,int>
#define ml map<ll,ll>
const int hell=1000000007;
//--------------------------------------------------//
            //--code from daksh_chhipa--//
//--------------------------------------------------// 
void showdq(deque<int> g)
{
    deque<int>::iterator it;
    for (it = g.begin(); it != g.end(); ++it)
        cout << '\t' << *it;
    cout << '\n';
}
bool isPerfectSquare(long long x)
{
    if (x >= 0) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;
   return (ceil(log2(n)) == floor(log2(n)));
}
unsigned countBits(unsigned int number)
{   
    return (int)log2(number)+1;
}
void counterint(int x){
    if(x>0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
}
void counteransh(int x){
    if(x>0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
}
//for(int i=0;i<n;i++){cin>>array[i];}
//for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);}
string s;
int main(){
    int t;
    cin>>t;
    while(t--){
int n,counter=0,even=0,odd=0;
cin>>n;
int array[n];
//3*i+5*j=//2x +5y+7z=n
//for(int i=0;i<n;i++){cin>>array[i];}
if(n%7==0){
    cout<<0<<" "<<0<<" "<<n/7<<endl;
}
else if(n%3==0){
        cout<<n/3<<" "<<0<<" "<<0<<endl;
}
else if(n%5==0){
        cout<<0<<" "<<n/5<<" "<<0<<endl;
}
else{
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if((n-(3*i+5*j))%7==0  && (n-(3*i+5*j))>=0){
                cout<<i<<" "<<j<<" "<<(n-(3*i+5*j))/7<<endl;
                counter=1;
                break;
            }
               else if((n-(5*i+7*j))%3==0 && (n-(5*i+7*j))>=0){
                cout<<(n-(5*i+7*j))/3<<" "<<i<<" "<<j<<endl;
                  counter=1;
                break;
            } 
            else if((n-(3*i+7*j))%3==0 && (n-(3*i+7*j))>=0){
                cout<<i<<" "<<(n-(3*i+7*j))/5<<" "<<j<<endl;
                  counter=1;
                break;
            }
        }
        if(counter==1){
            break;
        }
    }
    if(counter==0){
        cout<<"-1"<<endl;
    }
}

}
    return 0;
}


Comments

Submit
0 Comments
More Questions

WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array
2090. K Radius Subarray Averages
2091. Removing Minimum and Maximum From Array
6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines