답안 #556233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556233 2022-05-02T15:37:06 Z 600Mihnea Team Contest (JOI22_team) C++17
37 / 100
2000 ms 12568 KB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

struct T {
  int x;
  int y;
  int z;
  int tx;
  int ty;
  int tz;
};

bool cmp_x_inv(T a,T b) {
  return a.x>b.x;
}

typedef long long ll;
const int N=150000+7;
const int INF=(int)1e9+7;
int n,zm[N],invy[N],invz[N],value[N];
T a[N];
int aib1[N];

void clr1() {
  for (int i=1;i<=n;i++) aib1[i]=-INF;
}

int get1(int i) {
  int sol=-INF;
  while (i) {
    sol=max(sol,aib1[i]);
    i-=i&(-i);
  }
  return sol;
}

void upd1(int i,int x) {
  while (i<=n){
    aib1[i]=max(aib1[i],x);
    i+=i&(-i);
  }
}

map<int, int> aib[N];

void clr() {
  for (int i=1;i<=n;i++) aib[i].clear();
}

void upd(int x,int y,int val) {
  x=n+1-x;
  y=n+1-y;
  for (int i=x;i<=n;i+=i&(-i)) {
    for (int j=y;j<=n;j+=j&(-j)) {
      aib[i][j]=max(aib[i][j],val);
    }
  }
}

int get(int x,int y) {
  x=n+1-x;
  y=n+1-y;
  int sol=-INF;
  for (int i=x;i>=1;i-=i&(-i)) {
    for (int j=y;j>=1;j-=j&(-j)) {
      if (aib[i].count(j)) {
        sol=max(sol,aib[i][j]);
      }
    }
  }
  return sol;
}

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif

  home=0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }

  cin>>n;
  for (int i=1;i<=n;i++) {
    cin>>a[i].x>>a[i].y>>a[i].z;
  }
  sort(a+1,a+n+1,cmp_x_inv);
  {
    map<int, int> tx,ty,tz;
    for (int i=1;i<=n;i++) tx[a[i].x]=0,ty[a[i].y]=0,tz[a[i].z]=0;
    int ind;
    ind=0; for (auto &it:tx)it.second=++ind;
    ind=0; for (auto &it:ty)it.second=++ind, invy[ind]=it.first;
    ind=0; for (auto &it:tz)it.second=++ind, invz[ind]=it.first;
    for (int i=1;i<=n;i++) a[i].tx=tx[a[i].x], a[i].ty=ty[a[i].y], a[i].tz=tz[a[i].z];
  }
  int print=-1;

  for (int ITER=0;ITER<2;ITER++) {
    clr1();
    clr();

    for (int i=n;i>=1;i--) { /// optimize using aib
      zm[i]=get1(a[i].ty-1);
      upd1(a[i].ty,a[i].tz);
      if (zm[i]<=a[i].tz) zm[i]=-INF;

      if (1<=zm[i]&&zm[i]<=n) value[i]=invz[zm[i]]+a[i].y; else assert(zm[i]==-INF);
    }

    int last=n;
    while(last>=1){
      int first=last;
      while(first-1>=1&&a[first-1].x==a[first].x) first--;

      for (int i=first;i<=last;i++) {
        int best=-INF;
        int y=a[i].ty,z=a[i].tz;
        int best2=get(y+1,z+1);

        for (int j=last+1;j<=n;j++) {
          if (a[j].ty>=y+1&&zm[j]>=z+1) {
            best=max(best,value[j]);
          }
        }
        assert(best==best2);
        print=max(print,best+a[i].x);
      }

      for (int i=first;i<=last;i++) {
        if (zm[i]!=-INF) {
          assert(1<=zm[i]&&zm[i]<=n);
          upd(a[i].ty,zm[i],value[i]);
        }
      }
      last=first-1;
    }
    for (int i=1;i<=n;i++) swap(a[i].y,a[i].z), swap(a[i].ty,a[i].tz), swap(invz[i],invy[i]);
  }

  cout<<print<<"\n";
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:85:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7396 KB Output is correct
3 Correct 3 ms 7396 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 3 ms 7380 KB Output is correct
12 Correct 3 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7508 KB Output is correct
15 Correct 5 ms 7380 KB Output is correct
16 Correct 4 ms 7464 KB Output is correct
17 Correct 4 ms 7436 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 5 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 6 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 6 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7396 KB Output is correct
3 Correct 3 ms 7396 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 3 ms 7380 KB Output is correct
12 Correct 3 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7508 KB Output is correct
15 Correct 5 ms 7380 KB Output is correct
16 Correct 4 ms 7464 KB Output is correct
17 Correct 4 ms 7436 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 5 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 6 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 6 ms 7380 KB Output is correct
26 Correct 83 ms 9940 KB Output is correct
27 Correct 66 ms 8268 KB Output is correct
28 Correct 62 ms 8340 KB Output is correct
29 Correct 50 ms 8020 KB Output is correct
30 Correct 30 ms 7988 KB Output is correct
31 Correct 72 ms 7940 KB Output is correct
32 Correct 49 ms 7672 KB Output is correct
33 Correct 14 ms 7676 KB Output is correct
34 Correct 25 ms 8120 KB Output is correct
35 Correct 5 ms 7380 KB Output is correct
36 Correct 5 ms 7380 KB Output is correct
37 Correct 24 ms 7752 KB Output is correct
38 Correct 25 ms 7732 KB Output is correct
39 Correct 19 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7308 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Execution timed out 2093 ms 12568 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7308 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Execution timed out 2093 ms 12568 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7308 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Execution timed out 2093 ms 12568 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7308 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Execution timed out 2093 ms 12568 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7396 KB Output is correct
3 Correct 3 ms 7396 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 3 ms 7380 KB Output is correct
12 Correct 3 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7508 KB Output is correct
15 Correct 5 ms 7380 KB Output is correct
16 Correct 4 ms 7464 KB Output is correct
17 Correct 4 ms 7436 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 5 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 6 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 6 ms 7380 KB Output is correct
26 Correct 83 ms 9940 KB Output is correct
27 Correct 66 ms 8268 KB Output is correct
28 Correct 62 ms 8340 KB Output is correct
29 Correct 50 ms 8020 KB Output is correct
30 Correct 30 ms 7988 KB Output is correct
31 Correct 72 ms 7940 KB Output is correct
32 Correct 49 ms 7672 KB Output is correct
33 Correct 14 ms 7676 KB Output is correct
34 Correct 25 ms 8120 KB Output is correct
35 Correct 5 ms 7380 KB Output is correct
36 Correct 5 ms 7380 KB Output is correct
37 Correct 24 ms 7752 KB Output is correct
38 Correct 25 ms 7732 KB Output is correct
39 Correct 19 ms 7380 KB Output is correct
40 Correct 5 ms 7380 KB Output is correct
41 Correct 4 ms 7380 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
43 Correct 4 ms 7380 KB Output is correct
44 Correct 4 ms 7380 KB Output is correct
45 Correct 4 ms 7308 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 4 ms 7380 KB Output is correct
48 Correct 4 ms 7380 KB Output is correct
49 Correct 4 ms 7380 KB Output is correct
50 Execution timed out 2093 ms 12568 KB Time limit exceeded
51 Halted 0 ms 0 KB -