답안 #960108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960108 2024-04-09T16:33:33 Z Pety Volontiranje (COCI21_volontiranje) C++14
0 / 110
19 ms 47704 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e6+2;
int aib[N], dp[N], n, a[N];
set<int>LIS[N];
void update (int x, int val) {
  for (int i = x; i <= n; i += (i & -i))
    aib[i] = max(aib[i],val);
}
int query (int x) {
  int s= 0;
  for (int i = x; i; i -= (i & -i))
    s = max(s, aib[i]);
  return s;
}
 
int main () 
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] = x;
    dp[i] = query(x) + 1;
    update(x, dp[i]);
    LIS[dp[i]].insert(i);
    mx = max(mx, dp[i]);
  }
  vector<vector<int>>ans;
  while (LIS[mx].size()) {
    bool ok = 1;
    int last = *LIS[mx].rbegin();
    LIS[mx].erase(last);
    vector<int>sir;
    sir.push_back(last);
    for (int i = mx - 1; i >= 1; i--) {
      bool gasit = 0;
      for (auto it : LIS[i]) {
        if (it < last && a[it] < a[last]) {
          last = it;
          sir.push_back(last);
          gasit = 1;
          break;
        }
      }
      LIS[i].erase(last);
      if (!gasit) {ok = 0; break;}
    }
    if (!ok) break;
    reverse(sir.begin(), sir.end());
    ans.push_back(sir);
  }
  cout << ans.size() << " " << ans[0].size() << "\n";
  for (auto s : ans) {
    for (auto it : s)
      cout << it << " ";
    cout << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 47448 KB Output is correct
2 Correct 15 ms 47452 KB Output is correct
3 Correct 15 ms 47232 KB Output is correct
4 Correct 17 ms 47400 KB Output is correct
5 Correct 15 ms 47452 KB Output is correct
6 Correct 13 ms 47452 KB Output is correct
7 Correct 14 ms 47452 KB Output is correct
8 Correct 16 ms 47448 KB Output is correct
9 Correct 16 ms 47704 KB Output is correct
10 Correct 13 ms 47224 KB Output is correct
11 Correct 14 ms 47204 KB Output is correct
12 Correct 14 ms 47192 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 15 ms 47232 KB Output is correct
15 Correct 16 ms 47452 KB Output is correct
16 Correct 16 ms 47452 KB Output is correct
17 Incorrect 16 ms 47196 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 47448 KB Output is correct
2 Correct 15 ms 47452 KB Output is correct
3 Correct 15 ms 47232 KB Output is correct
4 Correct 17 ms 47400 KB Output is correct
5 Correct 15 ms 47452 KB Output is correct
6 Correct 13 ms 47452 KB Output is correct
7 Correct 14 ms 47452 KB Output is correct
8 Correct 16 ms 47448 KB Output is correct
9 Correct 16 ms 47704 KB Output is correct
10 Correct 13 ms 47224 KB Output is correct
11 Correct 14 ms 47204 KB Output is correct
12 Correct 14 ms 47192 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 15 ms 47232 KB Output is correct
15 Correct 16 ms 47452 KB Output is correct
16 Correct 16 ms 47452 KB Output is correct
17 Incorrect 16 ms 47196 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 47448 KB Output is correct
2 Correct 15 ms 47452 KB Output is correct
3 Correct 15 ms 47232 KB Output is correct
4 Correct 17 ms 47400 KB Output is correct
5 Correct 15 ms 47452 KB Output is correct
6 Correct 13 ms 47452 KB Output is correct
7 Correct 14 ms 47452 KB Output is correct
8 Correct 16 ms 47448 KB Output is correct
9 Correct 16 ms 47704 KB Output is correct
10 Correct 13 ms 47224 KB Output is correct
11 Correct 14 ms 47204 KB Output is correct
12 Correct 14 ms 47192 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 15 ms 47232 KB Output is correct
15 Correct 16 ms 47452 KB Output is correct
16 Correct 16 ms 47452 KB Output is correct
17 Incorrect 16 ms 47196 KB Output isn't correct
18 Halted 0 ms 0 KB -