Submission #705460

#TimeUsernameProblemLanguageResultExecution timeMemory
705460krizsu222Homework (CEOI22_homework)C++17
10 / 100
1071 ms524288 KiB
#include <bits/stdc++.h>
using namespace std;

int n,res; string s;
vector <vector <int>> perms;
bool vis[10];

void add(int a[])
{
    vector <int> act;

    for(int i=0; i<n; i++)
        act.push_back(a[i]);
    
    perms.push_back(act);
}

void calc(int a[])
{
    do
        add(a);
    while (next_permutation(a,a+n));
}

bool isnum(char x)
{
    return (x > 48 && x < 58);
}

int check(vector <int> act)
{
    int it = 0;
    string st = "";

    for(int i=0; i<s.size(); i++)
    {
        if(s[i] != 'm' && s[i] != 'i' && s[i] != 'a')
            st += s[i];
    }

    for(int i=0; i<st.size(); i++)
    {
        if(st[i] == '?')
        {
            st[i] = (act[it]+48);
            it++;
        }
    }

    while(st.size() != 1)
    {
        for(int i=3; i<st.size(); i++)
        {
            if(st[i] == ',' && isnum(st[i+1]) && isnum(st[i-1]))
            {
                if(st[i-3] == 'n')
                {
                    st[i-3] = min(st[i+1], st[i-1]);
                    st.erase(i-2, 5);
                }
                else
                {
                    st[i-3] = max(st[i+1], st[i-1]);
                    st.erase(i-2, 5);
                }

                break;
            }
        }
    }

    return (st[0]-48);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> s;

    for(int i=0; i<s.size(); i++)
        if(s[i] == '?') n++;

    int perm[n];
    for(int i=0; i<n; i++)
        perm[i] = i+1;

    calc(perm);

    for(int i=0; i<perms.size(); i++)
    {
        int temp = check(perms[i]);
        if(!vis[temp])
        {
            res++;
            vis[temp] = 1;
        }
    }

    cout << res;
}

Compilation message (stderr)

Main.cpp: In function 'int check(std::vector<int>)':
Main.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0; i<s.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0; i<st.size(); i++)
      |                  ~^~~~~~~~~~
Main.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i=3; i<st.size(); i++)
      |                      ~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i=0; i<s.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp:91:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=0; i<perms.size(); i++)
      |                  ~^~~~~~~~~~~~~
#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...