Submission #1273869

#TimeUsernameProblemLanguageResultExecution timeMemory
1273869phtungBinaria (CCO23_day1problem1)C++20
0 / 25
0 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

#define name "IO"
#define int long long 

const int inf = 1e18 + 7; 
const int maxn = 1e6 + 5;
const int mod = 1e6 + 3; 
int n, k, a[maxn]; 

namespace subtask2
{
    void solve()
    {
        int res = 0; 
        for(int mask = 1; mask < (1 << n); mask++)
        {
            int j = 1, sum = 0;  
            bool ok = 1; 
            for(int i = 1; i <= n; i++)
            {   
                sum += ((mask >> (i - 1)) & 1); 
                if(i - j + 1 < k) continue;     
                while(i - j + 1 > k)
                {
                    sum -= ((mask >> (j - 1)) & 1); 
                    j++; 
                }
                if(sum != a[j])
                {
                    ok = 0;
                    break; 
                }
            }

            if(ok) res++; 
        }

        cout << res << "\n"; 
    }
}

void solve()
{
    cin >> n >> k;
    for(int i = 1; i <= n - k + 1; i++) cin >> a[i];
    
    a[0] = a[1]; 
    for(int i = 1; i <= n - k + 1; i++)
    {
        if(a[i] > k || abs(a[i] - a[i - 1]) > 1)
        {
            cout << 0 << "\n";
            return; 
        }
    }

    if(n <= 10)
    {
        subtask2::solve();
        return; 
    }


}

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

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    clock_t start = clock(); 

    int t = 1;

    while(t--) solve(); 

    std::cerr << "Time: " << clock() - start << "ms\n";

    return 0; 

}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:73:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen (name".INP", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:74:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen (name".OUT", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...