Submission #1090373

# Submission time Handle Problem Language Result Execution time Memory
1090373 2024-09-18T09:48:47 Z quangminh412 Stove (JOI18_stove) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

/*
  John Watson
  https://codeforces.com/profile/quangminh98

  Mua Code nhu mua Florentino !!
*/

#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long

const int mod = 1e9 + 7;
const int maxn = 25;

int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; }
int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
int mul(int x, int y) { return (1ll * (x % mod) * (y % mod)) % mod; }

int power(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = mul(res, a);
        a = mul(a, a);
        b /= 2;
    }
    return res;
}

ll s;
int n;
ll f[maxn];

vector<int> fac, inv;
void init(int n)
{
    inv.resize(n + 2, 1);
    fac.resize(n + 2, 1);
    for (int i = 2; i <= n; i++)
    {
        fac[i] = mul(fac[i - 1], i);
        inv[i] = power(fac[i], mod - 2);
    }
}

int C(int k, ll n)
{
    if (k > n) return 0;
    int res = inv[k];
    for (int i = 0; i < k; i++)
        res = mul(res, n - i);
    return res;
}

signed main()
{
    if (fopen("FDEVU.INP", "r"))
    {
        freopen("FDEVU.INP", "r", stdin);
        freopen("FDEVU.OUT", "w", stdout);
    }
    faster();

    cin >> n >> s;
    init(20);
    for (int i = 1; i <= n; i++) cin >> f[i];
    
    ll cur = 0;
    for (int i = 1; i <= n; i++)
    	cur += f[i];
    if (cur < s)
    {
    	cout << 0 << '\n';
    	return 0;
	}

    int res = C(n - 1, n + s - 1);

    for (int mask = 1; mask < (1 << n); mask++)
    {
        ll sum = 0;
        int sz = 0;
        for (int i = 0; i < n; i++)
            if (mask >> i & 1)
            {
            	sz++;
            	sum += f[i + 1] + 1;
			}

        if (sz % 2 == 1)
            res = sub(res, C(n - 1, n - 1 + s - sum));
        else
            res = add(res, C(n - 1, n - 1 + s - sum));
    }

    cout << res << '\n';

    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen("FDEVU.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen("FDEVU.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -