Advertisement
Guest User

sursa boats

a guest
Dec 13th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream f ("boats.in");
  5. ofstream g ("boats.out");
  6. int n,m,i,j,a[1001][1001],l[1001],c[1001],cer,nrp,maxl,maxc;
  7. int main()
  8. {
  9. f >> cer >> n >> m;
  10. for(i=1; i<=n; i++)
  11. for(j=1; j<=m; j++) {
  12. f >> a[i][j];
  13. if(a[i][j]>0) {
  14. if(a[i-1][j]>0) {
  15. if(a[i-1][j]>1)c[a[i-1][j]]--;
  16. else nrp--;
  17. a[i][j]=a[i-1][j]+1;
  18. c[a[i][j]]++;
  19. maxc=max(a[i][j],maxc);
  20. }
  21. else if(a[i][j-1]>0) {
  22. if(a[i][j-1]>1)l[a[i][j-1]]--;
  23. else nrp--;
  24. a[i][j]=a[i][j-1]+1;
  25. l[a[i][j]]++;
  26. maxl=max(a[i][j],maxl);
  27. }
  28. else nrp++;
  29. }
  30. }
  31. if(cer==1) g << nrp;
  32. else {
  33. for(i=1; i<=maxl; i++) if(l[i]>0) g << "L " << i << " " << l[i] << "\n";
  34. for(i=1; i<=maxc; i++) if(c[i]>0) g << "C " << i << " " << c[i] << "\n";
  35. }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement