제출 #40563

#제출 시각아이디문제언어결과실행 시간메모리
40563Just_Solve_The_ProblemChessboard (IZhO18_chessboard)C++11
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define whatis(x) cout << #x << " is -> " << x << endl; const ll linf = (ll)1e18 + 7; const int N = (int)1e5 + 7; int x1[N], y1[N], x2[N], y2[N]; ll n; int k; ll ans = linf; inline ll gety(ll y,ll len){ if(y <= 0) return 0; ll res = (y / len) / 2 * len; if((y / len) & 1) res += y % len + 1; return res; } inline ll getx(ll x,ll len){ if(x <= 0) return 0; ll res = (x / len) / 2 * len; if((x / len) & 1) res += x % len + 1; return res; } void calc(ll len) { ll odd = 0, even = 0; for(int i = 1,xx,yy; i <= k; i++){ ll o1 = gety(y2[i], len) - gety(y1[i] - 1, len); ll e1 = (y2[i] - y1[i] + 1) - o1; ll o2 = getx(x2[i], len) - getx(x1[i] - 1, len); ll e2 = (x2[i] - x1[i] + 1) - o2; xx = x1[i] / len; yy = y1[i] / len; if(xx & 1) swap(o1,e1); if(yy & 1) swap(o2,e2); ll od = 0, ev = 0; if((xx + yy) & 1){ od = e1 * e2 + o1 * o2; } else{ od = o1 * e2 + e1 * o2; } ev = 1ll * (x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) - od; odd += od; even += ev; } ll cnt = 1ll * (n / len) * (n / len); ll res = min(cnt / 2 * len * len + even - odd, (cnt + 1) / 2 * len * len + odd - even); if(res < ans){ ans = res; } } main () { scanf("%lld %d", &n, &k); for (int i = 1; i <= k; i++) { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); a--; b--; c--; d--; x1[i] = a; y1[i] = b; x2[i] = c; y2[i] = d; } for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { calc(i); if (i != 1 && n / i != i) calc(n / i); } } printf("%I64d", ans); }

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp:11:16: error: 'int y1 [100007]' redeclared as different kind of symbol
 int x1[N], y1[N], x2[N], y2[N];
                ^
In file included from /usr/include/features.h:367:0,
                 from /usr/include/assert.h:35,
                 from /usr/include/c++/5/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:33,
                 from chessboard.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:251:1: note: previous declaration 'double y1(double)'
 __MATHCALL (y1,, (_Mdouble_));
 ^
chessboard.cpp: In function 'void calc(long long int)':
chessboard.cpp:34:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   ll o1 = gety(y2[i], len) - gety(y1[i] - 1, len);
                                       ^
chessboard.cpp:34:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   ll o1 = gety(y2[i], len) - gety(y1[i] - 1, len);
                                           ^
chessboard.cpp:34:41: error: invalid conversion from 'double (*)(double) throw ()' to 'long long int' [-fpermissive]
   ll o1 = gety(y2[i], len) - gety(y1[i] - 1, len);
                                         ^
chessboard.cpp:17:11: note:   initializing argument 1 of 'long long int gety(long long int, long long int)'
 inline ll gety(ll y,ll len){
           ^
chessboard.cpp:35:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   ll e1 = (y2[i] - y1[i] + 1) - o1;
                        ^
chessboard.cpp:35:24: error: invalid operands of types 'int' and 'double(double) throw ()' to binary 'operator-'
chessboard.cpp:39:12: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   yy = y1[i] / len;
            ^
chessboard.cpp:39:16: error: invalid operands of types 'double(double) throw ()' and 'long long int' to binary 'operator/'
   yy = y1[i] / len;
                ^
chessboard.cpp:49:49: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   ev = 1ll * (x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) - od;
                                                 ^
chessboard.cpp:49:49: error: invalid operands of types 'int' and 'double(double) throw ()' to binary 'operator-'
chessboard.cpp: At global scope:
chessboard.cpp:61:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:66:20: warning: pointer to a function used in arithmetic [-Wpointer-arith]
     x1[i] = a; y1[i] = b; x2[i] = c; y2[i] = d;
                    ^
chessboard.cpp:66:22: error: assignment of read-only location '*(y1 + ((sizetype)i))'
     x1[i] = a; y1[i] = b; x2[i] = c; y2[i] = d;
                      ^
chessboard.cpp:66:22: error: cannot convert 'int' to 'double(double) throw ()' in assignment
chessboard.cpp:74:22: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%I64d", ans);
                      ^
chessboard.cpp:62:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %d", &n, &k);
                           ^
chessboard.cpp:64:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d);
                                                         ^