Submission #1354794

#TimeUsernameProblemLanguageResultExecution timeMemory
1354794imchyGift Boxes (EGOI25_giftboxes)C++20
Compilation error
0 ms0 KiB
v#include <bits/stdc++.h>

using namespace std;

int main(){
    int t, n, id1=0, id2=0;
    cin>>t>>n;
    vector<int> c(n);
    map<int, int> p;

    for(int i=0;i<n;i++){
        cin>>c[i];
    }

    int i=0, j=n-1;

    while(!id1 || !id2){
        if(p[c[i]] && !id1){
            id1=i+1;

        }

        if(p[c[j]] && !id2){
            id2=j+1;
        }
        p[c[i]]=i+1;

        p[c[j]]=j+1;

        i++;
        j--;

    }
    
    map<int, int> k;
    int j1, j2;
    
    for(i=0;i<n;i++){
        if(k[c[i]]){
            j1=i;
            break;
        }
    }
    for(j=n-1;j>=0;j--){
        if(k[c[i]){
            j2=j;
            break;
        }
    }
    
    if(abs(id2-id1)<abs(j2-j1))
        cout<<min(id1-1, id2-1)<<" "<<max(id1-1, id2-1);
    
    else
        cout<<min(j1, j2)<<" "<<max(j1, j2);

    return 0;
}

Compilation message (stderr)

Main.cpp:1:2: error: stray '#' in program
    1 | v#include <bits/stdc++.h>
      |  ^
Main.cpp:1:1: error: 'v' does not name a type
    1 | v#include <bits/stdc++.h>
      | ^
Main.cpp: In function 'int main()':
Main.cpp:7:5: error: 'cin' was not declared in this scope
    7 |     cin>>t>>n;
      |     ^~~
Main.cpp:8:5: error: 'vector' was not declared in this scope
    8 |     vector<int> c(n);
      |     ^~~~~~
Main.cpp:8:12: error: expected primary-expression before 'int'
    8 |     vector<int> c(n);
      |            ^~~
Main.cpp:9:5: error: 'map' was not declared in this scope
    9 |     map<int, int> p;
      |     ^~~
Main.cpp:9:9: error: expected primary-expression before 'int'
    9 |     map<int, int> p;
      |         ^~~
Main.cpp:12:14: error: 'c' was not declared in this scope
   12 |         cin>>c[i];
      |              ^
Main.cpp:18:12: error: 'p' was not declared in this scope
   18 |         if(p[c[i]] && !id1){
      |            ^
Main.cpp:18:14: error: 'c' was not declared in this scope
   18 |         if(p[c[i]] && !id1){
      |              ^
Main.cpp:23:12: error: 'p' was not declared in this scope
   23 |         if(p[c[j]] && !id2){
      |            ^
Main.cpp:23:14: error: 'c' was not declared in this scope
   23 |         if(p[c[j]] && !id2){
      |              ^
Main.cpp:26:9: error: 'p' was not declared in this scope
   26 |         p[c[i]]=i+1;
      |         ^
Main.cpp:26:11: error: 'c' was not declared in this scope
   26 |         p[c[i]]=i+1;
      |           ^
Main.cpp:35:9: error: expected primary-expression before 'int'
   35 |     map<int, int> k;
      |         ^~~
Main.cpp:39:12: error: 'k' was not declared in this scope
   39 |         if(k[c[i]]){
      |            ^
Main.cpp:39:14: error: 'c' was not declared in this scope
   39 |         if(k[c[i]]){
      |              ^
Main.cpp:45:12: error: 'k' was not declared in this scope
   45 |         if(k[c[i]){
      |            ^
Main.cpp:45:14: error: 'c' was not declared in this scope
   45 |         if(k[c[i]){
      |              ^
Main.cpp:45:18: error: expected ']' before ')' token
   45 |         if(k[c[i]){
      |                  ^
      |                  ]
Main.cpp:51:8: error: 'abs' was not declared in this scope
   51 |     if(abs(id2-id1)<abs(j2-j1))
      |        ^~~
Main.cpp:52:9: error: 'cout' was not declared in this scope
   52 |         cout<<min(id1-1, id2-1)<<" "<<max(id1-1, id2-1);
      |         ^~~~
Main.cpp:52:15: error: 'min' was not declared in this scope; did you mean 'main'?
   52 |         cout<<min(id1-1, id2-1)<<" "<<max(id1-1, id2-1);
      |               ^~~
      |               main
Main.cpp:52:39: error: 'max' was not declared in this scope
   52 |         cout<<min(id1-1, id2-1)<<" "<<max(id1-1, id2-1);
      |                                       ^~~
Main.cpp:55:9: error: 'cout' was not declared in this scope
   55 |         cout<<min(j1, j2)<<" "<<max(j1, j2);
      |         ^~~~
Main.cpp:55:15: error: 'min' was not declared in this scope; did you mean 'main'?
   55 |         cout<<min(j1, j2)<<" "<<max(j1, j2);
      |               ^~~
      |               main
Main.cpp:55:33: error: 'max' was not declared in this scope
   55 |         cout<<min(j1, j2)<<" "<<max(j1, j2);
      |                                 ^~~