Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include<cmath>
- #include <cassert>
- using namespace std;
- #ifdef LOCAL_TESTING
- FILE *spoj_p_in, *spoj_p_out, *spoj_t_out;
- #define PIN "0.in"
- #define POUT "0.out"
- #define TOUT "out.txt"
- #define SPOJ_RV_POSITIVE 0
- #define SPOJ_RV_NEGATIVE -1
- int c = 0;
- void spoj_init() {
- spoj_p_in=fopen(PIN,"r");
- spoj_p_out=fopen(POUT, "r");
- spoj_t_out=fopen(TOUT, "r");
- }
- void spoj_assert(bool t) {
- assert(t);
- }
- #else
- #include<spoj.h>
- #endif
- char ans[1000000];
- void verify(int n, int len)
- {
- int n2 = n;
- int cnt = 0;
- int sz = strlen(ans);
- spoj_assert(sz==len);
- for(int i=0;i<sz;i++)
- {
- spoj_assert(ans[i]=='X' || ans[i]=='D');
- if(ans[i]=='X')
- cnt++;
- else
- n-=cnt;
- spoj_assert(n>=0);
- }
- spoj_assert(n==0);
- }
- int main()
- {
- spoj_init();
- int t,tmp;
- tmp = fscanf(spoj_p_in, "%d", &t);
- while(t--)
- {
- int n;
- tmp = fscanf(spoj_p_in, "%d", &n);
- int a = sqrtl(n);
- int b = (n+a-1)/a;
- int len = a+b;
- spoj_assert(fscanf(spoj_t_out, "%s", ans) == 1);
- verify(n,len);
- }
- #ifdef LOCAL_TESTING
- cout<<c;
- #endif
- return SPOJ_RV_POSITIVE;
- }
Add Comment
Please, Sign In to add comment