제출 #549381

#제출 시각아이디문제언어결과실행 시간메모리
549381joshjms선물상자 (IOI15_boxes)C++14
컴파일 에러
0 ms0 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << "\n"; const int mod = 1e9 + 7; int n, k, l, p[10000005], idx; int le, ri; ll dp[10000005][2]; ll ans; ll delivery(int N, int K, int L, int P[]) { n = N, k = K, l = L; for(int i = 0; i < n; i++) { if(P[i]) p[++idx] = P[i]; } n = idx; if(n == 0) return 0; le = 0, ri = 1; for(; ri <= n; ri++) { while(ri - le > k && le < ri) le++; } reverse(p + 1, p + n + 1); le = 0, ri = 1; for(; ri <= n; ri++) { while(ri - le > k && le < ri) le++; } ans = min(dp[p[1]][0], dp[p[n]][1]); for(int i = 2; i <= n; i++) { assert(p[i] >= 0 && p[i] < l && p[i - 1] >= 0 && p[i - 1] < l); ans = min(ans, dp[p[i]][0] + dp[p[i - 1]][1]); } return ans; } static char _buffer[1024]; static int _currentChar = 0; static int _charsNumber = 0; static FILE *_inputFile, *_outputFile; static inline int _read() { if (_charsNumber < 0) { exit(1); } if (!_charsNumber || _currentChar == _charsNumber) { _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile); _currentChar = 0; } if (_charsNumber <= 0) { return -1; } return _buffer[_currentChar++]; } static inline int _readInt() { int c, x, s; c = _read(); while (c <= 32) c = _read(); x = 0; s = 1; if (c == '-') { s = -1; c = _read(); } while (c > 32) { x *= 10; x += c - '0'; c = _read(); } if (s < 0) x = -x; return x; } int main() { _inputFile = stdin; _outputFile = stdout; int N, K, L, i; N = _readInt(); K = _readInt(); L = _readInt(); int *p = (int*)malloc(sizeof(int) * (unsigned int)N); for (i = 0; i < N; i++) { p[i] = _readInt(); } fprintf(_outputFile, "%lld\n", delivery(N, K, L, p)); return 0; }

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

boxes.cpp: In function 'int main()':
boxes.cpp:94:10: warning: declaration of 'p' shadows a global declaration [-Wshadow]
   94 |     int *p = (int*)malloc(sizeof(int) * (unsigned int)N);
      |          ^
boxes.cpp:15:14: note: shadowed declaration is here
   15 | int n, k, l, p[10000005], idx;
      |              ^
/usr/bin/ld: /tmp/ccmG53pX.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cct5rxUU.o:boxes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status