arjunarul

Custom Judge example

Mar 8th, 2019
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include<cmath>
  6. #include <cassert>
  7. using namespace std;
  8.  
  9.  
  10. #ifdef LOCAL_TESTING
  11. FILE *spoj_p_in, *spoj_p_out, *spoj_t_out;
  12. #define PIN "0.in"
  13. #define POUT "0.out"
  14. #define TOUT "out.txt"
  15. #define SPOJ_RV_POSITIVE 0
  16. #define SPOJ_RV_NEGATIVE -1
  17. int c = 0;
  18. void spoj_init() {
  19.   spoj_p_in=fopen(PIN,"r");
  20.   spoj_p_out=fopen(POUT, "r");
  21.   spoj_t_out=fopen(TOUT, "r");
  22. }
  23. void spoj_assert(bool t) {
  24.   assert(t);
  25. }
  26. #else
  27. #include<spoj.h>
  28. #endif
  29.  
  30.  
  31. char ans[1000000];
  32. void verify(int n, int len)
  33. {
  34.     int n2 = n;
  35.     int cnt = 0;
  36.     int sz = strlen(ans);
  37.     spoj_assert(sz==len);
  38.     for(int i=0;i<sz;i++)
  39.     {
  40.         spoj_assert(ans[i]=='X' || ans[i]=='D');
  41.         if(ans[i]=='X')
  42.             cnt++;
  43.         else
  44.             n-=cnt;
  45.         spoj_assert(n>=0);
  46.     }
  47.     spoj_assert(n==0);
  48. }
  49. int main()
  50. {
  51.     spoj_init();
  52.     int t,tmp;
  53.     tmp = fscanf(spoj_p_in, "%d", &t);
  54.     while(t--)
  55.     {
  56.         int n;
  57.         tmp = fscanf(spoj_p_in, "%d", &n);
  58.         int a = sqrtl(n);
  59.         int b = (n+a-1)/a;
  60.         int len = a+b;
  61.         spoj_assert(fscanf(spoj_t_out, "%s", ans) == 1);
  62.         verify(n,len);
  63.     }
  64.     #ifdef LOCAL_TESTING
  65.     cout<<c;
  66.     #endif
  67.     return SPOJ_RV_POSITIVE;
  68. }
Add Comment
Please, Sign In to add comment