답안 #341415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341415 2020-12-29T16:16:01 Z ivan_tudor Chessboard (IZhO18_chessboard) C++14
70 / 100
1196 ms 17576 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct eventhelp{
  int t;
  int l, r;
  int val;
  int type;
};
void add_int(int l, int r, long long val, long long &cnti, long long &cntp){
  int pare, impare;
  int dst = r - l + 1;
  pare = dst/2;
  impare = dst/2;
  if(dst%2 == 1){
    if(l%2 == 0)
      pare++;
    else
      impare++;
  }
  cnti += 1LL * impare * val;
  cntp += 1LL * pare * val;
}
vector<eventhelp> ev;
long long ans = LLONG_MAX;
int n;
bool cmpev(eventhelp a, eventhelp b){
  if(a.t == b.t)
    return a.type > b.type;
  return a.t < b.t;
}
long long imp[N], pr[N];
void solve(int len){
  vector<eventhelp> evc = ev;
  for(int i=len; i<=n;i+=len){
    evc.push_back({i, 0, 0, 0});
  }
  inplace_merge(evc.begin(), evc.begin() + ev.size(), evc.end(), cmpev);
  long long sumi = 0, acti = 0, sump = 0, actp = 0;
  for(auto e:evc){
    if(e.type != 0){
      int fgroup = (e.l - 1)/len + 1;
      int lgroup = (e.r - 1)/len + 1;
      if(fgroup  + 1 <= lgroup - 1){
        add_int(fgroup, lgroup, 1LL* e.val * len, sumi, sump);
        add_int(fgroup, lgroup, 1LL* e.type * len, acti, actp);
      }
      if(fgroup != lgroup){
        add_int(fgroup, fgroup, 1LL * e.val * (fgroup*len - e.l + 1), sumi, sump);
        add_int(fgroup, fgroup, 1LL * e.type * (fgroup*len - e.l + 1), acti, actp);

        add_int(lgroup, lgroup, 1LL * e.val * (e.r - (lgroup - 1)*len), sumi, sump);
        add_int(lgroup, lgroup, 1LL * e.type * (e.r - (lgroup - 1)*len), acti, actp);
      }
      if(fgroup == lgroup){
        add_int(fgroup, fgroup, 1LL * e.val * (e.r - e.l + 1), sumi, sump);
        add_int(fgroup, fgroup, 1LL * e.type * (e.r - e.l + 1), acti, actp);
      }
    }
    else{
      long long csumi, csump;
      csumi = sumi - acti * (n - e.t);
      csump = sump - actp * (n - e.t);
      imp[e.t/len] = csumi;
      pr[e.t/len] =csump;

    }
  }
  long long fans = 0, sans = 0;
  for(int i = 1; i<=n/len;i++){
    long long ci, cp;
    ci = imp[i] - imp[i-1];
    cp = pr[i] - pr[i -1];
    int nrp = (n/len)/2, nri = n/len - nrp;
    if(i %2 == 1){
      fans += 1LL*len*len*nri - ci + cp;
      sans += 1LL*len*len*nrp - cp + ci;
    }
    else{
      sans += 1LL*len*len*nri - ci + cp;
      fans += 1LL*len*len*nrp - cp + ci;
    }
  }
  ans = min(ans, sans);
  ans = min(ans, fans);
}
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int k;
  cin>>n>>k;
  for(int i=1;i<=k;i++){
    int x1, y1, x2, y2;
    cin>>x1>>y1>>x2>>y2;
    ev.push_back({x1, y1, y2, n - x1 + 1, 1});
    ev.push_back({x2, y1, y2,-(n - x2), -1});
  }
  sort(ev.begin(), ev.end(), cmpev);
  for(int d = 1; d<n; d++){
    if(n%d == 0)
      solve(d);
  }
  cout<<ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 9308 KB Output is correct
2 Correct 15 ms 2784 KB Output is correct
3 Correct 40 ms 9176 KB Output is correct
4 Correct 37 ms 6748 KB Output is correct
5 Correct 53 ms 8456 KB Output is correct
6 Correct 33 ms 5920 KB Output is correct
7 Correct 8 ms 2056 KB Output is correct
8 Correct 33 ms 5840 KB Output is correct
9 Correct 80 ms 13140 KB Output is correct
10 Correct 45 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 24 ms 4192 KB Output is correct
17 Correct 63 ms 11732 KB Output is correct
18 Correct 89 ms 13652 KB Output is correct
19 Correct 251 ms 12364 KB Output is correct
20 Correct 281 ms 13960 KB Output is correct
21 Correct 61 ms 11348 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 51 ms 6236 KB Output is correct
24 Correct 81 ms 12500 KB Output is correct
25 Correct 10 ms 1636 KB Output is correct
26 Correct 50 ms 8028 KB Output is correct
27 Correct 73 ms 9556 KB Output is correct
28 Correct 90 ms 13276 KB Output is correct
29 Correct 26 ms 4956 KB Output is correct
30 Correct 3 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 9308 KB Output is correct
2 Correct 15 ms 2784 KB Output is correct
3 Correct 40 ms 9176 KB Output is correct
4 Correct 37 ms 6748 KB Output is correct
5 Correct 53 ms 8456 KB Output is correct
6 Correct 33 ms 5920 KB Output is correct
7 Correct 8 ms 2056 KB Output is correct
8 Correct 33 ms 5840 KB Output is correct
9 Correct 80 ms 13140 KB Output is correct
10 Correct 45 ms 7516 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 24 ms 4192 KB Output is correct
27 Correct 63 ms 11732 KB Output is correct
28 Correct 89 ms 13652 KB Output is correct
29 Correct 251 ms 12364 KB Output is correct
30 Correct 281 ms 13960 KB Output is correct
31 Correct 61 ms 11348 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 51 ms 6236 KB Output is correct
34 Correct 81 ms 12500 KB Output is correct
35 Correct 10 ms 1636 KB Output is correct
36 Correct 50 ms 8028 KB Output is correct
37 Correct 73 ms 9556 KB Output is correct
38 Correct 90 ms 13276 KB Output is correct
39 Correct 26 ms 4956 KB Output is correct
40 Correct 3 ms 740 KB Output is correct
41 Correct 233 ms 15712 KB Output is correct
42 Correct 104 ms 15604 KB Output is correct
43 Correct 152 ms 15152 KB Output is correct
44 Correct 104 ms 16072 KB Output is correct
45 Correct 93 ms 14592 KB Output is correct
46 Correct 262 ms 16976 KB Output is correct
47 Correct 80 ms 13164 KB Output is correct
48 Correct 125 ms 14732 KB Output is correct
49 Correct 95 ms 14072 KB Output is correct
50 Correct 1069 ms 16240 KB Output is correct
51 Correct 1117 ms 16924 KB Output is correct
52 Correct 1032 ms 16032 KB Output is correct
53 Correct 1123 ms 16840 KB Output is correct
54 Correct 1026 ms 15880 KB Output is correct
55 Correct 1196 ms 17576 KB Output is correct
56 Correct 988 ms 15448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 69 ms 9308 KB Output is correct
10 Correct 15 ms 2784 KB Output is correct
11 Correct 40 ms 9176 KB Output is correct
12 Correct 37 ms 6748 KB Output is correct
13 Correct 53 ms 8456 KB Output is correct
14 Correct 33 ms 5920 KB Output is correct
15 Correct 8 ms 2056 KB Output is correct
16 Correct 33 ms 5840 KB Output is correct
17 Correct 80 ms 13140 KB Output is correct
18 Correct 45 ms 7516 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 24 ms 4192 KB Output is correct
35 Correct 63 ms 11732 KB Output is correct
36 Correct 89 ms 13652 KB Output is correct
37 Correct 251 ms 12364 KB Output is correct
38 Correct 281 ms 13960 KB Output is correct
39 Correct 61 ms 11348 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 51 ms 6236 KB Output is correct
42 Correct 81 ms 12500 KB Output is correct
43 Correct 10 ms 1636 KB Output is correct
44 Correct 50 ms 8028 KB Output is correct
45 Correct 73 ms 9556 KB Output is correct
46 Correct 90 ms 13276 KB Output is correct
47 Correct 26 ms 4956 KB Output is correct
48 Correct 3 ms 740 KB Output is correct
49 Correct 233 ms 15712 KB Output is correct
50 Correct 104 ms 15604 KB Output is correct
51 Correct 152 ms 15152 KB Output is correct
52 Correct 104 ms 16072 KB Output is correct
53 Correct 93 ms 14592 KB Output is correct
54 Correct 262 ms 16976 KB Output is correct
55 Correct 80 ms 13164 KB Output is correct
56 Correct 125 ms 14732 KB Output is correct
57 Correct 95 ms 14072 KB Output is correct
58 Correct 1069 ms 16240 KB Output is correct
59 Correct 1117 ms 16924 KB Output is correct
60 Correct 1032 ms 16032 KB Output is correct
61 Correct 1123 ms 16840 KB Output is correct
62 Correct 1026 ms 15880 KB Output is correct
63 Correct 1196 ms 17576 KB Output is correct
64 Correct 988 ms 15448 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Incorrect 1132 ms 16544 KB Output isn't correct
68 Halted 0 ms 0 KB -