답안 #1071405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071405 2024-08-23T07:11:08 Z kunzaZa183 Cultivation (JOI17_cultivation) C++17
60 / 100
2000 ms 23412 KB
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int r,c;
  cin>>r>>c;
  int n;
  cin>>n;
  vector<pair<int,int>> vpii(n);
  for(int i = 0; i < n;i++) {
    cin>>vpii[i].first>>vpii[i].second;
    vpii[i].first--, vpii[i].second--;
  }

  sort(vpii.begin(),vpii.end());

  /**/ cerr<<"VPII\n";
  /**/ for(auto a:vpii)
  /**/   cerr<<a.first<<' '<<a.second<<"\n";
  /**/ cerr<<"\n";

  const int maxn = 300;
  struct help{
    int mine,minw,mins;
  };
  help pcomp[maxn][maxn];

  for(int i = 0; i < n;i++) {
    set<int> si;
    multiset<int> diff;
    for(int j = i; j < n; j++) {
      /**/ cerr<<i<<' '<<j<<'\n';
      auto [it,trying] = si.insert(vpii[j].second);
      if(!trying) {
        pcomp[i][j].minw = *si.begin();
        pcomp[i][j].mine = c - 1 - *si.rbegin();
        if(!diff.empty())
          pcomp[i][j].mins = *diff.rbegin();
        continue;
      }
      auto bef = it, aft = it;

      aft++;
      if(it!=si.begin())
        bef--;

      if(it!=si.begin() && aft != si.end()) {
        diff.erase(diff.find(*aft - *bef - 1));
      }

      if(it!=si.begin())
        diff.insert(*it - *bef - 1);
      if(aft != si.end())
        diff.insert(*aft - *it - 1);

      pcomp[i][j].minw = *si.begin();
      pcomp[i][j].mine = c - 1 - *si.rbegin();
      if(!diff.empty())
        pcomp[i][j].mins = *diff.rbegin();
    }
  }

  /**/ cerr<<"PCOMP\n";
  /**/ for(int i = 0; i < n;i++)
  /**/   for(int j =0 ; j < n;j++)
  /**/     cerr<<i<<' '<<j<<' '<<pcomp[i][j].minw<<' '<<pcomp[i][j].mine<<" "<<pcomp[i][j].mins<<"\n";
  /**/ cerr<<"\n";

  int minn = INT_MAX,minso = INT_MAX, mins = 0;
  for(auto a:vpii)
    minn = min(minn,a.first), minso = min(minso, r - a.first - 1);
 
  for(int i = 0; i < vpii.size() - 1; i++) {
    mins = max(mins, vpii[i + 1].first - vpii[i].first - 1);
  }

  set<pair<int,int>> extra;

  set<int> extran,extras;
  extran.insert(0),extras.insert(0);
  for(int i = 0; i <n;i++) {
    extran.emplace(vpii[i].first );
    extras.emplace((r - 1) - (vpii[i].first));
  }

  set<int> gap;
  gap.insert(0);
  gap.insert(mins);
  for(int i = 0; i < n;i++)
    for(int j = i + 2; j < n;j++) {
      gap.emplace((vpii[j].first) - (vpii[i].first));
      gap.emplace(max(0,(vpii[j].first) - (vpii[i].first) - 1));
    }
  
  for(auto a:extran) {
    for(auto b:extras)
      if(a+b >= mins && a>= minn && b >= minso)
        extra.emplace(a,b);
  }
  for(auto a:extran)
    for(auto b:gap)
      if(b>=a && b >= mins && a>=minn && b-a >=minso)
        extra.emplace(a,b-a);

  for(auto a:extras)
    for(auto b:gap)
      if(b>=a && b >= mins && b-a>=minn && a >= minso)
        extra.emplace(b - a,a);

  /**/ cerr<<"EXTRA\n";
  /**/ cerr<<extra.size()<<"\n";
  /**/ for(auto a:extra)
  /**/   cerr<<a.first <<' '<<a.second<<'\n';

  /**/ cerr<<"\nN S\n";
  /**/ cerr<<minn<<' '<<minso<<' '<<mins<<"\n\n";

  long long minans = LLONG_MAX;
  for(auto a:extra) {
    map<int, vector<int>> mivi;
    /**/ cerr<<"EX "<<a.first<<" "<<a.second<<"\n";
    for(int i = 0; i < n;i++){
      int add = vpii[i].first - a.first,minus = vpii[i].first + 1 + a.second;

      add = max(add,0);
      mivi[add].push_back(i + 1);

      if(minus < r)
        mivi[minus].push_back(-(i+1)); 
    }

    int minw = 0, mine = 0, minsum = 0;
    set<int> curin;
    for(auto &a:mivi) {
      for(auto b:a.second)
        if(b>0)
          curin.insert(b - 1);
        else
          curin.erase(-b - 1);
      int sm = *curin.begin(), bg = *curin.rbegin();

      /**/ cerr<<sm<<' '<<bg<<'\n';
      
      assert((bg - sm + 1) == curin.size());

      minw = max(minw, pcomp[sm][bg].minw);
      mine = max(mine, pcomp[sm][bg].mine);
      minsum = max(minsum, pcomp[sm][bg].mins);
    }

    /**/ cerr<<minw<<' '<<mine<<' '<<minsum<<'\n';

    minans = min(minans, max((long long)minsum, (long long)mine + minw) + a.first + a.second);
  }

  cout<<minans<<'\n';

  return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for(int i = 0; i < vpii.size() - 1; i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from cultivation.cpp:1:
cultivation.cpp:143:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |       assert((bg - sm + 1) == curin.size());
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1444 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 5 ms 1368 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 2 ms 1400 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 2 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1444 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 5 ms 1368 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 2 ms 1400 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 2 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 17 ms 1372 KB Output is correct
18 Correct 119 ms 1520 KB Output is correct
19 Correct 61 ms 1372 KB Output is correct
20 Correct 9 ms 1368 KB Output is correct
21 Correct 179 ms 1756 KB Output is correct
22 Correct 487 ms 2084 KB Output is correct
23 Correct 28 ms 1500 KB Output is correct
24 Correct 778 ms 2520 KB Output is correct
25 Correct 545 ms 2136 KB Output is correct
26 Correct 1465 ms 3404 KB Output is correct
27 Correct 1457 ms 3352 KB Output is correct
28 Correct 721 ms 2544 KB Output is correct
29 Correct 1419 ms 3408 KB Output is correct
30 Correct 1407 ms 3296 KB Output is correct
31 Correct 1376 ms 3316 KB Output is correct
32 Correct 1395 ms 3372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1444 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 5 ms 1368 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 2 ms 1400 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 2 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 17 ms 1372 KB Output is correct
18 Correct 119 ms 1520 KB Output is correct
19 Correct 61 ms 1372 KB Output is correct
20 Correct 9 ms 1368 KB Output is correct
21 Correct 179 ms 1756 KB Output is correct
22 Correct 487 ms 2084 KB Output is correct
23 Correct 28 ms 1500 KB Output is correct
24 Correct 778 ms 2520 KB Output is correct
25 Correct 545 ms 2136 KB Output is correct
26 Correct 1465 ms 3404 KB Output is correct
27 Correct 1457 ms 3352 KB Output is correct
28 Correct 721 ms 2544 KB Output is correct
29 Correct 1419 ms 3408 KB Output is correct
30 Correct 1407 ms 3296 KB Output is correct
31 Correct 1376 ms 3316 KB Output is correct
32 Correct 1395 ms 3372 KB Output is correct
33 Correct 1074 ms 3664 KB Output is correct
34 Correct 1369 ms 4292 KB Output is correct
35 Correct 1543 ms 4352 KB Output is correct
36 Correct 1453 ms 4356 KB Output is correct
37 Correct 1258 ms 4176 KB Output is correct
38 Correct 1447 ms 4204 KB Output is correct
39 Correct 1439 ms 4352 KB Output is correct
40 Correct 1465 ms 4296 KB Output is correct
41 Correct 1185 ms 4036 KB Output is correct
42 Correct 1329 ms 3920 KB Output is correct
43 Correct 1376 ms 4312 KB Output is correct
44 Correct 1381 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 1932 KB Output is correct
2 Correct 1451 ms 3904 KB Output is correct
3 Correct 1421 ms 4056 KB Output is correct
4 Correct 1136 ms 3688 KB Output is correct
5 Correct 1340 ms 3780 KB Output is correct
6 Correct 471 ms 2384 KB Output is correct
7 Correct 26 ms 1372 KB Output is correct
8 Correct 640 ms 2508 KB Output is correct
9 Correct 536 ms 2392 KB Output is correct
10 Correct 1305 ms 4016 KB Output is correct
11 Correct 1365 ms 3912 KB Output is correct
12 Correct 1296 ms 3908 KB Output is correct
13 Correct 136 ms 1616 KB Output is correct
14 Correct 458 ms 2424 KB Output is correct
15 Correct 56 ms 1372 KB Output is correct
16 Correct 1378 ms 3844 KB Output is correct
17 Correct 1462 ms 4072 KB Output is correct
18 Correct 71 ms 1580 KB Output is correct
19 Correct 1439 ms 4064 KB Output is correct
20 Correct 869 ms 2968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 1932 KB Output is correct
2 Correct 1451 ms 3904 KB Output is correct
3 Correct 1421 ms 4056 KB Output is correct
4 Correct 1136 ms 3688 KB Output is correct
5 Correct 1340 ms 3780 KB Output is correct
6 Correct 471 ms 2384 KB Output is correct
7 Correct 26 ms 1372 KB Output is correct
8 Correct 640 ms 2508 KB Output is correct
9 Correct 536 ms 2392 KB Output is correct
10 Correct 1305 ms 4016 KB Output is correct
11 Correct 1365 ms 3912 KB Output is correct
12 Correct 1296 ms 3908 KB Output is correct
13 Correct 136 ms 1616 KB Output is correct
14 Correct 458 ms 2424 KB Output is correct
15 Correct 56 ms 1372 KB Output is correct
16 Correct 1378 ms 3844 KB Output is correct
17 Correct 1462 ms 4072 KB Output is correct
18 Correct 71 ms 1580 KB Output is correct
19 Correct 1439 ms 4064 KB Output is correct
20 Correct 869 ms 2968 KB Output is correct
21 Execution timed out 2021 ms 23412 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1444 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 5 ms 1368 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 2 ms 1400 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 2 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 17 ms 1372 KB Output is correct
18 Correct 119 ms 1520 KB Output is correct
19 Correct 61 ms 1372 KB Output is correct
20 Correct 9 ms 1368 KB Output is correct
21 Correct 179 ms 1756 KB Output is correct
22 Correct 487 ms 2084 KB Output is correct
23 Correct 28 ms 1500 KB Output is correct
24 Correct 778 ms 2520 KB Output is correct
25 Correct 545 ms 2136 KB Output is correct
26 Correct 1465 ms 3404 KB Output is correct
27 Correct 1457 ms 3352 KB Output is correct
28 Correct 721 ms 2544 KB Output is correct
29 Correct 1419 ms 3408 KB Output is correct
30 Correct 1407 ms 3296 KB Output is correct
31 Correct 1376 ms 3316 KB Output is correct
32 Correct 1395 ms 3372 KB Output is correct
33 Correct 1074 ms 3664 KB Output is correct
34 Correct 1369 ms 4292 KB Output is correct
35 Correct 1543 ms 4352 KB Output is correct
36 Correct 1453 ms 4356 KB Output is correct
37 Correct 1258 ms 4176 KB Output is correct
38 Correct 1447 ms 4204 KB Output is correct
39 Correct 1439 ms 4352 KB Output is correct
40 Correct 1465 ms 4296 KB Output is correct
41 Correct 1185 ms 4036 KB Output is correct
42 Correct 1329 ms 3920 KB Output is correct
43 Correct 1376 ms 4312 KB Output is correct
44 Correct 1381 ms 4452 KB Output is correct
45 Correct 287 ms 1932 KB Output is correct
46 Correct 1451 ms 3904 KB Output is correct
47 Correct 1421 ms 4056 KB Output is correct
48 Correct 1136 ms 3688 KB Output is correct
49 Correct 1340 ms 3780 KB Output is correct
50 Correct 471 ms 2384 KB Output is correct
51 Correct 26 ms 1372 KB Output is correct
52 Correct 640 ms 2508 KB Output is correct
53 Correct 536 ms 2392 KB Output is correct
54 Correct 1305 ms 4016 KB Output is correct
55 Correct 1365 ms 3912 KB Output is correct
56 Correct 1296 ms 3908 KB Output is correct
57 Correct 136 ms 1616 KB Output is correct
58 Correct 458 ms 2424 KB Output is correct
59 Correct 56 ms 1372 KB Output is correct
60 Correct 1378 ms 3844 KB Output is correct
61 Correct 1462 ms 4072 KB Output is correct
62 Correct 71 ms 1580 KB Output is correct
63 Correct 1439 ms 4064 KB Output is correct
64 Correct 869 ms 2968 KB Output is correct
65 Execution timed out 2021 ms 23412 KB Time limit exceeded
66 Halted 0 ms 0 KB -