Submission #317991

# Submission time Handle Problem Language Result Execution time Memory
317991 2020-10-31T05:50:10 Z pg1210 Miners (IOI07_miners) C++14
15 / 100
3 ms 768 KB
#include <bits/stdc++.h>

using namespace std;
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define TESTS wez(testow); while(testow--) //for multilple cases problems
#define whileZ int T; getI(T); while(T--) // the same as above
#define getS(x) scanf("%s", x) //get a char* string
#define clr(a,x) memset(a,x,sizeof(a)) //set elements of array to some value
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end())
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end())
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
// for debug
inline void pisz(int n) { printf("%d\n",n); }
// count rects in n*m grid
inline int rectCount(int n, int m) { return (m * n * (n + 1) * (m + 1)) / 4; }
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
#define MAXN 10000
//for vectors
#define UNIQUEA(a,n) unique(a,a+n)-a
#define UNIQUEV(v) v.erase(unique(v.begin(),v.end()),v.end())
#define INSERT(index, str) str.insert(index,str)
#define REPLACE(str,start,count,new_str) str.replace(start,count,new_str)
#define COUNT(str,ch) count(str.begin(),str.end(),ch)
#define ERASE(str,index) str.erase(str.begin()+index)
#define MAXA(a,n) *max_element(a,a+n)
#define MINA(a,n) *min_element(a,a+n)
#define REV(v) reverse(v.begin(),v.end())
#define SUM(v) accumulate(v.begin(),v.end(),0)
#define MAXV(v) *max_element(v.begin(),v.end())
#define MINV(v) *min_element(v.begin(),v.end())
#define pb push_back
typedef int elem_t;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi rem(vi vect, int num){
    vi myVector = vect;
    std::vector<int>::iterator position = std::find(myVector.begin(), myVector.end(), num);
    if (position != myVector.end()){ // == myVector.end() means the element was not found
        myVector.erase(position);
    }
    return myVector;
}
typedef pair<int,int> ii;
// directions
const int fx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; }

const string numbers = "0123456789ABCDEFGHI";

string baseConv(int n, int b){
    int currQ = n;
    string str, output;
    while(true){
        str+=numbers[currQ%b];
        currQ /= b;
        if (currQ == 0) break;
    }
    FFE(i, str.size()-1, 0){
        output+=str[i];
    }
    return output;
}

int countOut(string str) {
    int ctr = 0;
    F(i,2,str.size()) {
        if (str[i] == str[i-1] and str[i-2] == str[i-1]) ctr++;
        else if (str[i] == str[i-1] and str[i-1] != str[i-2]) ctr+=2;
        else if (str[i] == str[i-2] and str[i-1] != str[i-2]) ctr+=2;
        else ctr+=3;
    }
    return ctr;
}


void solveQues() {
    //code
    int n;
    cin >> n;
    vector<char> food(n);
    string first = "", second = "";
    int ans = 0;
    F(i,0,n) {
        cin >> food[i];
        if (i == 0) {
            first+=food[i];
            ans+=1;
        } else {
            if (i == 1 and first[0] != food[i]) {
                first+=food[i];
                ans+=2;
            } else {
                if (i == 1) {
                    second+=food[i];
                    ans+=1;
                }
            }
            if (i > 1) {
                int ctr1 = 0, ctr2 = 0;
                ctr1+=count(first.end()-2, first.end(), food[i]);
                ctr2+=count(second.end()-2, second.end(), food[i]);
                if (ctr1 > ctr2) {
                    second+=food[i];
                } else {
                    first+=food[i];
                }
            }
        }
    }
    ans+=countOut(first);
    ans+=countOut(second);
    cout << ans << endl;
    return;
}

int main(){
    IOS;
    cin.tie(NULL);
    cout.tie(NULL);

    solveQues();
    return 0;
}

Compilation message

miners.cpp: In function 'int countOut(std::string)':
miners.cpp:13:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
......
  105 |     F(i,2,str.size()) {
      |       ~~~~~~~~~~~~~~                
miners.cpp:105:5: note: in expansion of macro 'F'
  105 |     F(i,2,str.size()) {
      |     ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 768 KB Output isn't correct