제출 #1368908

#제출 시각아이디문제언어결과실행 시간메모리
1368908mahribanGift Boxes (EGOI25_giftboxes)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
int fr[500009], ls[500009];
bool vis[500009];
int a[500009];
int main(){
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i ++){
        cin >> a[i];
        if (!fr[a[i]])fr[a[i]] = i;
        ls[a[i]] = i;
    }
    int r = -1, l = 0;
    for (int i = m; i >= 1; i --){
        if (ls[a[i]] != i){r = i;break;}
    }
    for (int i = 1; i <= m; i ++){
        if (fr[a[i]] != i){l = i; break;}
    }
    for (r = m; r >= 1; r --){
        if (ls[a[r]] != r)break;
        l = min(l, fr[a[r]]);
        if (mx < m - r + l){
            mx = m - r + l;
            ansl = l;
            ansr = r - 1;        
        }
    }
    cout << ansl - 1 << ' ' << ansr - 1 << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:26: error: the value of 'm' is not usable in a constant expression
   24 |         if (mx < m - r + l){
      |                          ^
Main.cpp:7:12: note: 'int m' is not const
    7 |     int n, m;
      |            ^
Main.cpp:24:13: error: 'mx' was not declared in this scope; did you mean 'm'?
   24 |         if (mx < m - r + l){
      |             ^~
      |             m
Main.cpp:26:13: error: 'ansl' was not declared in this scope
   26 |             ansl = l;
      |             ^~~~
Main.cpp:27:13: error: 'ansr' was not declared in this scope
   27 |             ansr = r - 1;
      |             ^~~~
Main.cpp:30:13: error: 'ansl' was not declared in this scope
   30 |     cout << ansl - 1 << ' ' << ansr - 1 << endl;
      |             ^~~~
Main.cpp:30:32: error: 'ansr' was not declared in this scope
   30 |     cout << ansl - 1 << ' ' << ansr - 1 << endl;
      |                                ^~~~