Submission #56794397


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
// -----------------------------------------------------macros------------------------------------------------------------------
#define int long long int
#define vi vector<int>
#define pb push_back
#define in(a, b, arr) for(int i = a; i < b; i++){cin>>arr[i];}
#define out(a, b, arr) for(int i = a; i < b; i++){cout<<arr[i]<<' ';}cout<<endl;
//------------------------------------------------------ constants ------------------------------------------------------------
int mod=1e9+7;
// ------------------------------------------------------basic functions----------------------------------------------------------------
void primeSieve(vector<int> &sieve, int N)
{
// mark 1 and 0 as not prime
sieve[1] = sieve[0] = 0;
// start from 2 and mark all multiples of ith number(prime) as not prime
for (int i = 2; i <= N ; i++)
{
int p = sieve[i];
if (p==1)
{
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
using namespace std;
// -----------------------------------------------------macros------------------------------------------------------------------
#define int long long int
#define vi vector<int>
#define pb push_back
#define in(a, b, arr) for(int i = a; i < b; i++){cin>>arr[i];}
#define out(a, b, arr) for(int i = a; i < b; i++){cout<<arr[i]<<' ';}cout<<endl;
//------------------------------------------------------ constants ------------------------------------------------------------
int mod=1e9+7;
// ------------------------------------------------------basic functions----------------------------------------------------------------
void primeSieve(vector<int> &sieve, int N)
{
    // mark 1 and 0 as not prime
    sieve[1] = sieve[0] = 0;
    // start from 2 and mark all multiples of ith number(prime) as not prime
    for (int i = 2; i <= N ; i++)
    {
            int p = sieve[i];
            if (p==1)
            {
                for (int j = i*i; j <= N; j = j+i)
                {
                    // marking j as not prime
                    sieve[j] = 0;
                }
            }
    }
}
int power(int a,int b)
{
    a%=mod;
    int res=1;
    while(b>0)
    {
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res%mod;

}
vector<int> primeFactors(int n)
{
    vector<int> v;
    // Print the number of 2s that divide n 
    while (n % 2 == 0)
    {
        v.push_back(2);
        n = n/2;
    }
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n 
        while (n % i == 0)
        {
            v.push_back(i);
            n = n/i;
        }
    }
    // This condition is to handle the case when n
    // is a prime number greater than 2 
    if (n > 2) 
        v.push_back(n);
    return v;

}
vector<int> printDivisors(int n) 
{
    vector<int> v;
    // Note that this loop runs till square root
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            // If divisors are equal, print only one
            if (n/i == i)
                v.push_back(i);
            else{ // Otherwise print both
                v.push_back(i);
                v.push_back(n/i);
            }
        }
    }
    return v;
}
// -------------------------------------------------------advanced functions-----------------------------------------------------
int add(int x, int y)
{
    return (x%mod + y%mod)%mod;

}
int subtract(int x, int y)
{
    return (x%mod - y%mod + mod)%mod;

}
int multiply(int x, int y)
{
    return ((x%mod)*(y%mod))%mod;

}
int divide(int x, int y)
{
    return multiply(x, power(y, mod-2));

}
int factorial(int n)
{
    int fact[n+1];
    fact[0]=1;
    for (int i = 1; i <=n; i++)
    {
        fact[i] = multiply(fact[i-1], i);
    }
    return fact[n];

}
int inverse(int x)
{
    return power(x, mod-2);

}
int nCr(int n, int r)
{
    return multiply(factorial(n), multiply(inverse(factorial(r)), inverse(factorial(n-r))));
}
//------------------------------------------------------------------main function---------------------------------------

void solve(int i, int n, int k, vector<int>& r, vector<int>& comp, int sum, vector<vector<int>>& ans)
{
    if(i==n)
    {
        if(sum%k==0) ans.push_back(comp);
        return;
    }

    for(int j=1; j<=r[i]; j++)
    {
        comp.push_back(j);
        solve(i+1, n, k, r, comp, sum+j, ans);
        comp.pop_back();
    }
}

int32_t main()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
      int n,k;
      cin>>n>>k;
      vector<int> r(n);
      for(int i=0; i<n; i++) cin>>r[i];
      vector<vector<int>> ans;
      vector<int> comp;
      solve(0, n, k, r, comp, 0, ans);
      sort(ans.begin(), ans.end());
      for(int i=0; i<ans.size(); i++)
      {
        for (int j = 0; j < ans[i].size(); j++)
        {
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
      }
    }
    return 0;
}

Submission Info

Submission Time
Task C - Enumerate Sequences
User isha_406
Language C++ 20 (gcc 12.2)
Score 300
Code Size 4231 Byte
Status AC
Exec Time 298 ms
Memory 23596 KB

Compile Error

Main.cpp: In function ‘int32_t main()’:
Main.cpp:163:21: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::vector<long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  163 |       for(int i=0; i<ans.size(); i++)
      |                    ~^~~~~~~~~~~
Main.cpp:165:27: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  165 |         for (int j = 0; j < ans[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 33
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 3384 KB
sample_02.txt AC 1 ms 3480 KB
sample_03.txt AC 1 ms 3576 KB
test_01.txt AC 1 ms 3368 KB
test_02.txt AC 1 ms 3472 KB
test_03.txt AC 1 ms 3372 KB
test_04.txt AC 298 ms 23596 KB
test_05.txt AC 198 ms 16228 KB
test_06.txt AC 150 ms 13072 KB
test_07.txt AC 121 ms 11336 KB
test_08.txt AC 100 ms 9708 KB
test_09.txt AC 87 ms 8688 KB
test_10.txt AC 76 ms 8208 KB
test_11.txt AC 67 ms 7428 KB
test_12.txt AC 58 ms 7292 KB
test_13.txt AC 1 ms 3504 KB
test_14.txt AC 1 ms 3504 KB
test_15.txt AC 1 ms 3480 KB
test_16.txt AC 1 ms 3552 KB
test_17.txt AC 1 ms 3516 KB
test_18.txt AC 1 ms 3500 KB
test_19.txt AC 1 ms 3452 KB
test_20.txt AC 1 ms 3512 KB
test_21.txt AC 1 ms 3496 KB
test_22.txt AC 1 ms 3516 KB
test_23.txt AC 1 ms 3488 KB
test_24.txt AC 1 ms 3492 KB
test_25.txt AC 1 ms 3472 KB
test_26.txt AC 1 ms 3540 KB
test_27.txt AC 1 ms 3572 KB
test_28.txt AC 1 ms 3496 KB
test_29.txt AC 1 ms 3648 KB
test_30.txt AC 1 ms 3412 KB


2025-04-04 (Fri)
05:21:49 +00:00