CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home  » November 2009 (Contest X) » Help the judge » All Submissions » sriram [130761]
0
Your rating: None

CodeChef submission 130761 (C++ 4.0.0-8)

CodeChef submission 130761 (C++ 4.0.0-8) plaintext list. Status: WA, problem J6, contest NOV09. By srirams (sriram), 2009-11-11 12:40:12.
  1. using namespace std;
  2. #include <vector>
  3. #include <list>
  4. #include <map>
  5. #include <set>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <bitset>
  10. #include <algorithm>
  11. #include <functional>
  12. #include <numeric>
  13. #include <utility>
  14. #include <sstream>
  15. #include <iostream>
  16. #include <iomanip>
  17. #include <cstdio>
  18. #include <cmath>
  19. #include <cstdlib>
  20. #include <ctime>
  21. #define REP(i,n) for(i=0;i<n;i++)
  22. #define FOR(i,A,n) for(i=A;i<n;i++)
  23. #define sz(c) (signed int) c.size()
  24. #define pb(c) push_back(c)
  25. #define INF (int) 1e9
  26. #define all(c) c.begin(),c.end()
  27. #define GI(t) scanf("%d",&t);
  28. typedef long long LL;
  29. typedef vector<int> VI;
  30. typedef pair<int,int> PII;
  31.  
  32. struct Person {
  33. vector<int>evi; // Evidence Nos
  34. int status; // indicates involvement/non-involvement/uncertain
  35. bool visit;
  36. };
  37.  
  38. typedef struct Person person;
  39.  
  40. #define inv 1
  41. #define ninv -1
  42. #define not_sure 0
  43.  
  44. int DFS(vector<person>& v,vector<PII>& R,int i);
  45.  
  46. int main() {
  47. int i,j;
  48. int n,k;
  49. int t;
  50. GI(t);
  51. int l,m;
  52. PII s;
  53. int p,q;
  54. bool f1,f2;
  55. while(t--) {
  56. GI(n);GI(k);
  57. if(k==0) {printf("MULTIPLE\n");continue;} // trivial case - no evidence
  58. vector<person>v;
  59. vector<PII>R;
  60. person P;
  61. map<PII,int>M;
  62. int flag=0;
  63. // Initialise the N persons
  64. REP(i,n) {
  65. P.status=not_sure;
  66. P.visit=false;
  67. v.pb(P);
  68. }
  69. REP(i,k) {
  70. GI(p);GI(q);
  71. s.first=p;s.second=q;
  72. R.pb(s); // Store the evidence, we may need it later
  73. l=abs(p);
  74. m=abs(q);
  75. f1=true;
  76. f2=true;
  77. // Check for clinching evidence
  78. if(l==m) { // same person
  79. if(p==q) { // true evidence
  80. if((v[l-1].status==inv && p<0) || (v[l-1].status==ninv && p>0)) {
  81. printf("CONFLICT\n");
  82. flag=1;
  83. break;
  84. }
  85. else {
  86. if(p>0) v[l-1].status=inv;
  87. else v[l-1].status=ninv;
  88. }
  89. }
  90. }
  91. else { // Different person
  92. // Test each part separately
  93. if((v[l-1].status==inv && p<0) || (v[l-1].status==ninv && p>0)) {
  94. // 1st part is false
  95. f1=false;
  96. }
  97. if((v[m-1].status==inv && q<0) || (v[m-1].status==ninv && q>0)) {
  98. // 2nd part is false;
  99. f2=false;
  100. }
  101. if(!f1 && !f2) {
  102. printf("CONFLICT\n");
  103. flag=1;
  104. break;
  105. }
  106. if(!f1) {
  107. // 2nd part is true
  108. v[m-1].status=(q>0)?inv:ninv;
  109. continue;
  110. }
  111. if(!f2) {
  112. // 1st part is true
  113. v[l-1].status=(p>0)?inv:ninv;
  114. continue;
  115. }
  116. // Check for boolean table
  117. // Consider 2 vars A&B, the possible values are (00,01,10,11)
  118. // 0 is = not involved
  119. // For 00,score =1,01 score=2,10 score=4,11 score =8
  120. // Store the score in map<PII>, pair shud be unique,so make it ordered
  121. if(l<m) {
  122. s.first=l;s.second=m;
  123. }
  124. else {
  125. s.first=m;s.second=l;
  126. swap(p,q);
  127. }
  128. if(p>0) {
  129. if(q>0)
  130. M[s]+=8;
  131. else M[s]+=4;
  132. }
  133. else {
  134. if(q>0)
  135. M[s]+=2;
  136. else M[s]+=1;
  137. }
  138.  
  139.  
  140. // We dont have clinching evidence now,so store it for later use
  141. v[l-1].evi.pb(i);
  142. v[m-1].evi.pb(i);
  143.  
  144. }
  145. }
  146. if(flag) continue;
  147. // Get answer from boolean table if possible
  148. map<PII,int>::iterator it;
  149. for(it=M.begin();it!=M.end();it++) {
  150. s=it->first;
  151. //cout<<s.first<<" "<<s.second<<" "<<M[s]<<endl;
  152. // 2 of the values in the table are avail,so we can determine l or m for some scores.
  153. if(M[s]==3) {
  154. l=s.first;
  155. if(v[l-1].status==inv) {
  156. printf("CONFLICT\n");
  157. flag=1;
  158. break;
  159. }
  160. else
  161. v[l-1].status=ninv;
  162. }
  163. if(M[s]==12) {
  164. l=s.first;
  165. if(v[l-1].status==ninv) {
  166. printf("CONFLICT\n");
  167. flag=1;
  168. break;
  169. }
  170. else
  171. v[l-1].status=inv;
  172.  
  173. }
  174. if(M[s]==5) {
  175. m=s.second;
  176. if(v[m-1].status==inv) {
  177. printf("CONFLICT\n");
  178. flag=1;
  179. break;
  180. }
  181. else
  182. v[m-1].status=ninv;
  183. }
  184. if(M[s]==10) {
  185. m=s.second;
  186. if(v[m-1].status==ninv) {
  187. printf("CONFLICT\n");
  188. flag=1;
  189. break;
  190. }
  191. else
  192. v[m-1].status=inv;
  193.  
  194. }
  195.  
  196. // 3 values in the table are avail, so we can determine value of l & m uniquely.
  197. if(M[s]==7) {
  198. l=s.first;m=s.second;
  199. if(v[l-1].status==inv || v[m-1].status==inv) {
  200. printf("CONFLICT\n");
  201. flag=1;
  202. break;
  203. }
  204. else {
  205. v[l-1].status=ninv;
  206. v[m-1].status=ninv;
  207. }
  208. }
  209. if(M[s]==11) {
  210. l=s.first;m=s.second;
  211. if(v[l-1].status==inv || v[m-1].status==ninv) {
  212. printf("CONFLICT\n");
  213. flag=1;
  214. break;
  215. }
  216. else {
  217. v[l-1].status=ninv;
  218. v[m-1].status=inv;
  219. }
  220.  
  221. }
  222. if(M[s]==13) {
  223. l=s.first;m=s.second;
  224. if(v[l-1].status==ninv || v[m-1].status==inv) {
  225. printf("CONFLICT\n");
  226. flag=1;
  227. break;
  228. }
  229. else {
  230. v[l-1].status=inv;
  231. v[m-1].status=ninv;
  232. }
  233.  
  234. }
  235. if(M[s]==14) {
  236. l=s.first;m=s.second;
  237. if(v[l-1].status==ninv || v[m-1].status==ninv) {
  238. printf("CONFLICT\n");
  239. flag=1;
  240. break;
  241. }
  242. else {
  243. v[l-1].status=inv;
  244. v[m-1].status=inv;
  245. }
  246.  
  247. }
  248. // All 4 values available, no solution possible
  249. if(M[s]==15) {
  250. printf("CONFLICT\n");
  251. flag=1;
  252. break;
  253. }
  254. }
  255. if(flag) continue;
  256. // Ok, now we have some results, we need more
  257. // DFS seems to be good
  258. REP(i,n) {
  259. if((v[i].status==inv || v[i].status==ninv) && v[i].visit==false) {
  260. int ret=DFS(v,R,i);
  261. if(ret==-1) {
  262. flag=1;
  263. break;
  264. }
  265. }
  266. }
  267.  
  268.  
  269. if(flag) continue;
  270.  
  271. REP(i,n) {
  272. if(v[i].status==not_sure) {
  273. flag=1;
  274. printf("MULTIPLE\n");
  275. break;
  276. }
  277. }
  278. if(!flag) printf("UNIQUE\n") ;
  279. }
  280. return 0;
  281. }
  282.  
  283. int DFS(vector<person>& v,vector<PII>& R,int i) {
  284. int j;
  285. PII s;
  286. int l,m,p,q;
  287. int flag=0;
  288. int ret=0;
  289. REP(j,sz(v[i].evi)) {
  290. s=R[v[i].evi[j]];
  291. p=s.first;q=s.second;
  292. l=abs(p);m=abs(q);
  293. bool f1=true,f2=true;
  294. if((v[l-1].status==inv && p<0) || (v[l-1].status==ninv && p>0)) {
  295. // 1st part is false
  296. f1=false;
  297. }
  298. if((v[m-1].status==inv && q<0) || (v[m-1].status==ninv && q>0)) {
  299. // 2nd part is false;
  300. f2=false;
  301. }
  302. if(!f1 && !f2) {
  303. printf("CONFLICT\n");
  304. flag=1;
  305. break;
  306. }
  307. if(!f1) {
  308. // 2nd part is true
  309. if(v[m-1].status==not_sure) {
  310. v[m-1].status=(q>0)?inv:ninv;
  311. if(v[m-1].visit==false) {
  312. ret=DFS(v,R,m-1);
  313. if(ret==-1) break;
  314. }
  315. }
  316. }
  317. if(!f2) {
  318. // 1st part is true
  319. if(v[l-1].status==not_sure) {
  320. v[l-1].status=(p>0)?inv:ninv;
  321. if(v[l-1].visit==false) {
  322. ret=DFS(v,R,l-1);
  323. if(ret==-1) break;
  324. }
  325. }
  326. }
  327. //cout<<v[l-1].status<<" "<<v[m-1].status<<endl;
  328. }
  329. v[i].visit=true;
  330. if(flag==1 || ret==-1) return -1;
  331. else return 0;
  332. }


Comments

  • Login or Register to post a comment.

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com