답안 #785511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785511 2023-07-17T09:47:42 Z andecaandeci Global Warming (CEOI18_glo) C++17
75 / 100
2000 ms 6188 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, x; cin >> n >> x;
  if(x==0) {
    vector<int> a(n); for(int &p : a) cin >> p;
  vector<int> dp; int ans=1;
    for(int p : a) {
      auto it=lower_bound(dp.begin(), dp.end(), p);
      if(it==dp.end()) dp.push_back(p);
      else *it=p;
    }
    ans=dp.size();
    cout << ans << '\n';
  } else if(x<=5 && n<=50000) {
    vector<int> a, b;
      while(n--) {
      int p; cin >> p;
      vector<int> tempaa=a;
      auto it=lower_bound(tempaa.begin(), tempaa.end(), p);
      if(it==tempaa.end()) tempaa.push_back(p);
      else *it=p;
      vector<int> tempba=b;
      it=lower_bound(tempba.begin(), tempba.end(), p);
      if(it==tempba.end()) tempba.push_back(p);
      else *it=p;
      if(tempaa.size()>tempba.size()) a=tempaa;
      else a=tempba; p-=x;
      it=lower_bound(b.begin(), b.end(), p); 
      if(it==b.end()) b.push_back(p);
      else *it=p;
    }
    int ans=max((int)a.size(), (int)b.size());
    cout << ans << '\n';
    } else if(x==(int)1e9) {
      int ans=1;
      vector<int> a(n), b, pre(n);
      for(int &p : a) cin >> p;
      b=a; reverse(b.begin(), b.end());
      vector<int> dp;
      for(int i=0; i<n; i++) {
        int l=0, r=dp.size()-1, idx=-1;
        while(l<=r) {
          int mid=l+r>>1;
          if(b[i]>=dp[mid]) r=mid-1, idx=mid;
          else l=mid+1;
      }
      if(idx==-1) dp.push_back(b[i]);
      else dp[idx]=b[i];
      pre[i]=dp.size();
    }
    dp.clear();
    for(int i=0; i<n-1; i++) {
      auto it=lower_bound(dp.begin(), dp.end(), a[i]);
      if(it==dp.end()) dp.push_back(a[i]);
      else *it=a[i];
      ans=max(ans, (int)dp.size()+pre[n-i-2]);
    }
    cout << ans << '\n';
    } else {
      vector<int> a(n); for(int &p : a) cin >> p;
      vector<int> dp; int ans=1;
      for(int i=0; i<n; i++) {
          dp.clear();
          vector<int> temp=a;
          for(int k=i; k<n; k++) temp[k]+=x;
          for(int p : temp) {
            auto it=lower_bound(dp.begin(), dp.end(), p);
            if(it==dp.end()) dp.push_back(p);
            else *it=p;    
            }
          ans=max(ans, (int)dp.size());
          
      }
      cout << ans << '\n';
    }
    return 0;
}   

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:30:7: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   30 |       else a=tempba; p-=x;
      |       ^~~~
glo.cpp:30:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   30 |       else a=tempba; p-=x;
      |                      ^
glo.cpp:46:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |           int mid=l+r>>1;
      |                   ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 14 ms 212 KB Output is correct
20 Correct 11 ms 340 KB Output is correct
21 Correct 11 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 11 ms 340 KB Output is correct
24 Correct 11 ms 352 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 8 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1896 KB Output is correct
2 Correct 25 ms 1900 KB Output is correct
3 Correct 25 ms 1876 KB Output is correct
4 Correct 25 ms 1904 KB Output is correct
5 Correct 15 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 444 KB Output is correct
2 Correct 19 ms 428 KB Output is correct
3 Correct 20 ms 452 KB Output is correct
4 Correct 1031 ms 3072 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1588 ms 3028 KB Output is correct
7 Correct 18 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2668 KB Output is correct
2 Correct 18 ms 2664 KB Output is correct
3 Correct 37 ms 4996 KB Output is correct
4 Correct 20 ms 6188 KB Output is correct
5 Correct 11 ms 3344 KB Output is correct
6 Correct 18 ms 5880 KB Output is correct
7 Correct 21 ms 5876 KB Output is correct
8 Correct 15 ms 2704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 14 ms 212 KB Output is correct
20 Correct 11 ms 340 KB Output is correct
21 Correct 11 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 11 ms 340 KB Output is correct
24 Correct 11 ms 352 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 8 ms 340 KB Output is correct
27 Correct 25 ms 1896 KB Output is correct
28 Correct 25 ms 1900 KB Output is correct
29 Correct 25 ms 1876 KB Output is correct
30 Correct 25 ms 1904 KB Output is correct
31 Correct 15 ms 3028 KB Output is correct
32 Correct 19 ms 444 KB Output is correct
33 Correct 19 ms 428 KB Output is correct
34 Correct 20 ms 452 KB Output is correct
35 Correct 1031 ms 3072 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1588 ms 3028 KB Output is correct
38 Correct 18 ms 340 KB Output is correct
39 Correct 17 ms 2668 KB Output is correct
40 Correct 18 ms 2664 KB Output is correct
41 Correct 37 ms 4996 KB Output is correct
42 Correct 20 ms 6188 KB Output is correct
43 Correct 11 ms 3344 KB Output is correct
44 Correct 18 ms 5880 KB Output is correct
45 Correct 21 ms 5876 KB Output is correct
46 Correct 15 ms 2704 KB Output is correct
47 Execution timed out 2069 ms 1888 KB Time limit exceeded
48 Halted 0 ms 0 KB -