Submission #453149

#TimeUsernameProblemLanguageResultExecution timeMemory
453149fuad27Highway design (CEOI12_highway)C++14
Compilation error
0 ms0 KiB
#include <stdlib.h> #include <iostream> #include <string> #include "office.h" #define _MaxN 100001 using namespace std; bool _Init = true; int _digi = 129723562; int _N, _Qnum, _maxQ1, _maxQ2, _maxQ4; int _Apa[_MaxN]; void _Fin(bool OK, string S){ int point=0; if (OK) { if (_Qnum <= _maxQ4) { point = 4; S=" <=N/2+2"; } else if (_Qnum <= _maxQ2) { point = 2; S=" <=2N/3"; } else { point = 1; S=" <=N-3"; } cout<<point<<endl; cout<<"Correct"<<endl; cout<<"#Questions= "<<_Qnum<<S<<endl; cout<<_digi<<endl; exit(0); } cout<<"0"<<endl; cout<<S<<endl; cout<<"#Questions= "<<_Qnum<<endl; cout<<_digi<<endl; exit(0); } /*_Fin*/ void _doInit(){ int x; cin>>_N; for (x = 1; x <= _N; x++) { _Apa[x] = -1; } _Qnum = 0; _maxQ1 = _N - 3; _maxQ2 = _N * 2 / 3; _maxQ4 = _N / 2+2; } /*diInit*/ int GetN(){ if (_Init) { _doInit(); _Init = false; } return _N; } /*GetN*/ int _Find(int x){ int k; int Nx = x; while (_Apa[Nx] > 0) { Nx = _Apa[Nx]; } while (x != Nx) { k = _Apa[x]; _Apa[x] = Nx; x = k; } return Nx; } /*_Find*/ int _Unio(int nn, int mm){ int k; if (nn == mm) { return nn; } if (_Apa[nn] > _Apa[mm]) { k = nn; nn = mm; mm = k; } _Apa[nn] += _Apa[mm]; _Apa[mm] = nn; return nn; } /*_Unio*/ int isOnLine(int x, int y, int z){ int nx, ny, nz,nn; int nxn = 0, nyn = 0, nzn = 0; int i; if (_Init) { _Fin(0, "Protocol error"); } if (x < 1 || x > _N || y < 1 || y > _N || z < 1 || z > _N) { _Fin(0, "Protocol error"); } _Qnum++; if (_Qnum > _maxQ1) _Fin(false, "Too many questions"); if (x == y || y == z || y==z) { return 1; } nx = _Find(x); ny = _Find(y); nz = _Find(z); if (nx == ny && ny == nz) { return 1; } nxn = -_Apa[nx]; nyn = -_Apa[ny]; nzn = -_Apa[nz]; nn=nxn+nyn+nzn; if (nx==ny) nn-=nyn; if (nx==nz) nn-=nzn; if (ny==nz) nn-=nzn; if (nn <= _N - 3) { nx = _Unio(nx, ny); nx = _Unio(nx, nz); return 1; } return 0; } /*isOnLine*/ void Answer(int a1, int b1, int a2, int b2){ int na1, nb1, na2, nb2; if (a1 < 1 || a1 > _N || b1 < 1 || b1 > _N || a2 < 1 || a2 > _N || b2 < 1 || b2 > _N || a1==b1 || a2==b2) { _Fin(0, "Protocol error"); } na1 = _Find(a1); nb1 = _Find(b1); na2 = _Find(a2); nb2 = _Find(b2); if (na1==nb1){ if( (-_Apa[na1]==_N-3) && (na2!=na1) && (nb2!=na1) || (na2==nb2) && (na1!=na2) && (-(_Apa[na1]+_Apa[na2])>_N-3) ) _Fin(true, "Correct"); else _Fin(false, "Wrong answer"); }else if (na2==nb2){ if( (-_Apa[na2]==_N-3) && (na1!=na2) && (nb1!=na2) || (na1==nb1)&&(na1!=na2)&&(-(_Apa[na1]+_Apa[na2])>_N-3) ) _Fin(true, "Correct"); else _Fin(false, "Wrong answer"); }else{ _Fin(false, "Wrong answer"); } _Fin(true, "Correct"); }

Compilation message (stderr)

highway.cpp: In function 'int isOnLine(int, int, int)':
highway.cpp:91:7: warning: unused variable 'i' [-Wunused-variable]
   91 |   int i;
      |       ^
highway.cpp: In function 'void Answer(int, int, int, int)':
highway.cpp:136:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  136 |       if( (-_Apa[na1]==_N-3) && (na2!=na1) && (nb2!=na1) ||
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
highway.cpp:142:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  142 |       if( (-_Apa[na2]==_N-3) && (na1!=na2) && (nb1!=na2) ||
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
office.c: In function 'int isOnLine(int, int, int)':
office.c:85:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   85 |     _Fin(0, "Protocol error");
      |             ^~~~~~~~~~~~~~~~
office.c:88:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   88 |     _Fin(0, "Protocol error");
      |             ^~~~~~~~~~~~~~~~
office.c:92:17: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   92 |     _Fin(false, "Too many questions");
      |                 ^~~~~~~~~~~~~~~~~~~~
office.c:83:7: warning: unused variable 'i' [-Wunused-variable]
   83 |   int i;
      |       ^
office.c: In function 'void Answer(int, int, int, int)':
office.c:123:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  123 |     _Fin(0, "Protocol error");
      |             ^~~~~~~~~~~~~~~~
office.c:128:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  128 |       if( (-_Apa[na1]==_N-3) && (na2!=na1) && (nb2!=na1) ||
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
office.c:130:21: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  130 |          _Fin(true, "Correct");
      |                     ^~~~~~~~~
office.c:132:22: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  132 |          _Fin(false, "Wrong answer");
      |                      ^~~~~~~~~~~~~~
office.c:134:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  134 |       if( (-_Apa[na2]==_N-3) && (na1!=na2) && (nb1!=na2) ||
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
office.c:136:21: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  136 |          _Fin(true, "Correct");
      |                     ^~~~~~~~~
office.c:138:22: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  138 |          _Fin(false, "Wrong answer");
      |                      ^~~~~~~~~~~~~~
office.c:140:19: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  140 |       _Fin(false, "Wrong answer");
      |                   ^~~~~~~~~~~~~~
office.c:142:14: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  142 |   _Fin(true, "Correct");
      |              ^~~~~~~~~
office.c:120:27: warning: unused variable 'pont' [-Wunused-variable]
  120 |   int na1, nb1, na2, nb2, pont;
      |                           ^~~~
office.c: In function 'void _doInit()':
office.c:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d", &_N);
      |     ~~~~~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccqYtTzb.o:(.bss+0x61a90): multiple definition of `_Qnum'; /tmp/cctnHP6d.o:(.bss+0x61a90): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.bss+0x61a84): multiple definition of `_maxQ4'; /tmp/cctnHP6d.o:(.bss+0x61a84): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.bss+0x61a88): multiple definition of `_maxQ2'; /tmp/cctnHP6d.o:(.bss+0x61a88): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o: in function `_doInit()':
office.c:(.text+0x70): multiple definition of `_doInit()'; /tmp/cctnHP6d.o:highway.cpp:(.text+0x2f0): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.bss+0x61a94): multiple definition of `_N'; /tmp/cctnHP6d.o:(.bss+0x61a94): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.bss+0x0): multiple definition of `_Apa'; /tmp/cctnHP6d.o:(.bss+0x0): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.bss+0x61a8c): multiple definition of `_maxQ1'; /tmp/cctnHP6d.o:(.bss+0x61a8c): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o: in function `GetN()':
office.c:(.text+0xf0): multiple definition of `GetN()'; /tmp/cctnHP6d.o:highway.cpp:(.text+0x370): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.data+0x4): multiple definition of `_Init'; /tmp/cctnHP6d.o:(.data+0x4): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o: in function `_Find(int)':
office.c:(.text+0x130): multiple definition of `_Find(int)'; /tmp/cctnHP6d.o:highway.cpp:(.text+0x3b0): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o: in function `_Unio(int, int)':
office.c:(.text+0x170): multiple definition of `_Unio(int, int)'; /tmp/cctnHP6d.o:highway.cpp:(.text+0x3f0): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o: in function `isOnLine(int, int, int)':
office.c:(.text+0x1d0): multiple definition of `isOnLine(int, int, int)'; /tmp/cctnHP6d.o:highway.cpp:(.text+0x450): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o: in function `Answer(int, int, int, int)':
office.c:(.text+0x3f0): multiple definition of `Answer(int, int, int, int)'; /tmp/cctnHP6d.o:highway.cpp:(.text+0x720): first defined here
/usr/bin/ld: /tmp/ccqYtTzb.o:(.data+0x0): multiple definition of `_digi'; /tmp/cctnHP6d.o:(.data+0x0): first defined here
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status