Submission #778644

# Submission time Handle Problem Language Result Execution time Memory
778644 2023-07-10T14:09:05 Z Sandarach151 Carnival (CEOI14_carnival) C++17
100 / 100
16 ms 312 KB
#include<bits/stdc++.h>
using namespace std;

int getNum(vector<int> vect){
	if(vect.size()==1){
		return 1;
	}
    cout << vect.size();
    for(int i=0; i<vect.size(); i++){
        cout << ' ' << vect[i];
    }
    cout << endl;
    int a;
    cin >> a;
    return a;
}

vector<int> func(int cur, vector<int> vect){ // vect exculdes cur
    if(vect.size()==1){
        return vect;
    }
    else{
        int mid = vect.size()/2;
        vector<int> temp1, temp2, ans1, ans2;
        for(int i=0; i<mid; i++){
            temp1.push_back(vect[i]);
        }
        for(int i=mid; i<vect.size(); i++){
            temp2.push_back(vect[i]);
        }
        int a = getNum(temp1);
        temp1.push_back(cur);
        int b = getNum(temp1);
        if(b==a){
            temp1.pop_back();
            ans1 = func(cur, temp1);
        }
        int c = getNum(temp2);
        temp2.push_back(cur);
        int d = getNum(temp2);
        if(c==d){
            temp2.pop_back();
            ans2 = func(cur, temp2);
        }
        for(int i=0; i<ans2.size(); i++){
            ans1.push_back(ans2[i]);
        }
        return ans1;
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> vect(n);
    for(int i=1; i<=n; i++){
        vect[i-1]=i;
    }
    vector<int> ans(n);
    int pos = 1;
    while(vect.size()>0){
        if(vect.size()==1){
            ans[vect[0]-1]=pos;
            break;
        }
        else{
            ans[vect[0]-1]=pos;
            int cur = vect[0];
            vector<int> temp;
            for(int i=1; i<vect.size(); i++){
                temp.push_back(vect[i]);
            }
            int a = getNum(temp);
            temp.push_back(vect[0]);
            int b = getNum(temp);
            temp.pop_back();
            if(a==b){
                vector<int> temp2 = func(cur, temp);
                for(int i=0; i<temp2.size(); i++){
                    ans[temp2[i]-1]=pos;
                    for(int j=0; j<vect.size(); j++){
                        if(vect[j]==temp2[i]){
                            vect.erase(vect.begin()+j);
                            break;
                        }
                    }
                }
                vect.erase(vect.begin());
                pos++;
            }
            else{
                vect.erase(vect.begin());
                pos++;
            }
        }
    }
    cout << 0;
    for(int i=0; i<n; i++){
		cout << ' ' << ans[i];
	}
    return 0;
}

Compilation message

carnival.cpp: In function 'int getNum(std::vector<int>)':
carnival.cpp:9:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i=0; i<vect.size(); i++){
      |                  ~^~~~~~~~~~~~
carnival.cpp: In function 'std::vector<int> func(int, std::vector<int>)':
carnival.cpp:28:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i=mid; i<vect.size(); i++){
      |                        ~^~~~~~~~~~~~
carnival.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int i=0; i<ans2.size(); i++){
      |                      ~^~~~~~~~~~~~
carnival.cpp: In function 'int main()':
carnival.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int i=1; i<vect.size(); i++){
      |                          ~^~~~~~~~~~~~
carnival.cpp:79:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |                 for(int i=0; i<temp2.size(); i++){
      |                              ~^~~~~~~~~~~~~
carnival.cpp:81:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                     for(int j=0; j<vect.size(); j++){
      |                                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 16 ms 208 KB Output is correct
3 Correct 10 ms 312 KB Output is correct
4 Correct 6 ms 308 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 13 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 11 ms 312 KB Output is correct
3 Correct 7 ms 308 KB Output is correct
4 Correct 5 ms 208 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 15 ms 308 KB Output is correct
4 Correct 6 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 15 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 208 KB Output is correct
2 Correct 10 ms 208 KB Output is correct
3 Correct 9 ms 308 KB Output is correct
4 Correct 6 ms 308 KB Output is correct
5 Correct 7 ms 300 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 15 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 208 KB Output is correct
2 Correct 10 ms 304 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 12 ms 308 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 6 ms 312 KB Output is correct
7 Correct 6 ms 208 KB Output is correct