답안 #1071409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071409 2024-08-23T07:13:06 Z kunzaZa183 Cultivation (JOI17_cultivation) C++17
60 / 100
2000 ms 16468 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 1 ms 1368 KB Output is correct
2 Correct 1 ms 1432 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 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 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1432 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 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 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 3 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 7 ms 1548 KB Output is correct
22 Correct 19 ms 1576 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 34 ms 1580 KB Output is correct
25 Correct 23 ms 1368 KB Output is correct
26 Correct 47 ms 1496 KB Output is correct
27 Correct 45 ms 1372 KB Output is correct
28 Correct 28 ms 1368 KB Output is correct
29 Correct 42 ms 1372 KB Output is correct
30 Correct 46 ms 1372 KB Output is correct
31 Correct 46 ms 1372 KB Output is correct
32 Correct 45 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1432 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 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 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 3 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 7 ms 1548 KB Output is correct
22 Correct 19 ms 1576 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 34 ms 1580 KB Output is correct
25 Correct 23 ms 1368 KB Output is correct
26 Correct 47 ms 1496 KB Output is correct
27 Correct 45 ms 1372 KB Output is correct
28 Correct 28 ms 1368 KB Output is correct
29 Correct 42 ms 1372 KB Output is correct
30 Correct 46 ms 1372 KB Output is correct
31 Correct 46 ms 1372 KB Output is correct
32 Correct 45 ms 1368 KB Output is correct
33 Correct 10 ms 1368 KB Output is correct
34 Correct 48 ms 1372 KB Output is correct
35 Correct 57 ms 1500 KB Output is correct
36 Correct 59 ms 1372 KB Output is correct
37 Correct 42 ms 1368 KB Output is correct
38 Correct 53 ms 1368 KB Output is correct
39 Correct 51 ms 1368 KB Output is correct
40 Correct 55 ms 1568 KB Output is correct
41 Correct 29 ms 1368 KB Output is correct
42 Correct 40 ms 1372 KB Output is correct
43 Correct 59 ms 1560 KB Output is correct
44 Correct 49 ms 1572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1624 KB Output is correct
2 Correct 30 ms 1884 KB Output is correct
3 Correct 31 ms 1884 KB Output is correct
4 Correct 25 ms 1824 KB Output is correct
5 Correct 35 ms 1628 KB Output is correct
6 Correct 12 ms 1624 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 14 ms 1692 KB Output is correct
9 Correct 14 ms 1624 KB Output is correct
10 Correct 29 ms 1884 KB Output is correct
11 Correct 29 ms 1884 KB Output is correct
12 Correct 28 ms 1892 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 12 ms 1684 KB Output is correct
15 Correct 2 ms 1368 KB Output is correct
16 Correct 28 ms 1884 KB Output is correct
17 Correct 31 ms 1884 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 31 ms 1940 KB Output is correct
20 Correct 17 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1624 KB Output is correct
2 Correct 30 ms 1884 KB Output is correct
3 Correct 31 ms 1884 KB Output is correct
4 Correct 25 ms 1824 KB Output is correct
5 Correct 35 ms 1628 KB Output is correct
6 Correct 12 ms 1624 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 14 ms 1692 KB Output is correct
9 Correct 14 ms 1624 KB Output is correct
10 Correct 29 ms 1884 KB Output is correct
11 Correct 29 ms 1884 KB Output is correct
12 Correct 28 ms 1892 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 12 ms 1684 KB Output is correct
15 Correct 2 ms 1368 KB Output is correct
16 Correct 28 ms 1884 KB Output is correct
17 Correct 31 ms 1884 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 31 ms 1940 KB Output is correct
20 Correct 17 ms 1628 KB Output is correct
21 Execution timed out 2049 ms 16468 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1432 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 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 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 3 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 7 ms 1548 KB Output is correct
22 Correct 19 ms 1576 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 34 ms 1580 KB Output is correct
25 Correct 23 ms 1368 KB Output is correct
26 Correct 47 ms 1496 KB Output is correct
27 Correct 45 ms 1372 KB Output is correct
28 Correct 28 ms 1368 KB Output is correct
29 Correct 42 ms 1372 KB Output is correct
30 Correct 46 ms 1372 KB Output is correct
31 Correct 46 ms 1372 KB Output is correct
32 Correct 45 ms 1368 KB Output is correct
33 Correct 10 ms 1368 KB Output is correct
34 Correct 48 ms 1372 KB Output is correct
35 Correct 57 ms 1500 KB Output is correct
36 Correct 59 ms 1372 KB Output is correct
37 Correct 42 ms 1368 KB Output is correct
38 Correct 53 ms 1368 KB Output is correct
39 Correct 51 ms 1368 KB Output is correct
40 Correct 55 ms 1568 KB Output is correct
41 Correct 29 ms 1368 KB Output is correct
42 Correct 40 ms 1372 KB Output is correct
43 Correct 59 ms 1560 KB Output is correct
44 Correct 49 ms 1572 KB Output is correct
45 Correct 7 ms 1624 KB Output is correct
46 Correct 30 ms 1884 KB Output is correct
47 Correct 31 ms 1884 KB Output is correct
48 Correct 25 ms 1824 KB Output is correct
49 Correct 35 ms 1628 KB Output is correct
50 Correct 12 ms 1624 KB Output is correct
51 Correct 1 ms 1372 KB Output is correct
52 Correct 14 ms 1692 KB Output is correct
53 Correct 14 ms 1624 KB Output is correct
54 Correct 29 ms 1884 KB Output is correct
55 Correct 29 ms 1884 KB Output is correct
56 Correct 28 ms 1892 KB Output is correct
57 Correct 4 ms 1372 KB Output is correct
58 Correct 12 ms 1684 KB Output is correct
59 Correct 2 ms 1368 KB Output is correct
60 Correct 28 ms 1884 KB Output is correct
61 Correct 31 ms 1884 KB Output is correct
62 Correct 3 ms 1372 KB Output is correct
63 Correct 31 ms 1940 KB Output is correct
64 Correct 17 ms 1628 KB Output is correct
65 Execution timed out 2049 ms 16468 KB Time limit exceeded
66 Halted 0 ms 0 KB -