読者です 読者をやめる 読者になる 読者になる

SRM529 Div2 250 && 500

250

int savedPawnCount(vector <int> start) {
    int result;

    for(int i=start.size() - 1;i > 0;i--) {
        start[i-1] += start[i] / 2;
    }

    result = start[0];
    return result;
  }


500

vector<string> split(string str, string delim)
        {
            vector<string> result;
            int cutAt;
            while( (cutAt = str.find_first_of(delim)) != str.npos )
            {
                if(cutAt > 0)
                {
                    result.push_back(str.substr(0, cutAt));
                }
                str = str.substr(cutAt + 1);
            }
            if(str.length() > 0)
            {
                result.push_back(str);
            }
            return result;
        }

        vector <string> getSortedList(vector <string> kings) {
            vector <string> result;
            vector <string> s;

            s.push_back("I");
            s.push_back("II");
            s.push_back("III");
            s.push_back("IV");
            s.push_back("V");
            s.push_back("VI");
            s.push_back("VII");
            s.push_back("VIII");
            s.push_back("IX");
            s.push_back("X");

            for(int i=10;i < 39;i++) {
                string hoge = "";
                for(int j=0;j < i/10;j++) {
                    hoge += s[9];
                }
                hoge += s[i%10];
                s.push_back(hoge);
            }
            s.push_back("XL");

            for(int i=0;i < 9;i++) {
                string hoge = s[39] + s[i];
                s.push_back(hoge);
            }
            s.push_back("L");

            //for(int i=0;i< s.size();i++) {
            //cout << s[i] << endl;
            //} 
            
            typedef pair<string, string> value_type;
            vector<value_type> kings_s;
            for(int i=0;i < kings.size();i++) {
                vector<string>hoge = split(kings[i]," ");
                kings_s.push_back(value_type(hoge[0],hoge[1]));
            }

            sort(kings_s.begin(), kings_s.end());


            typedef pair<int, string> value_type_i;
            for(int i=0;i < kings_s.size();i++) {
                vector<value_type_i> hogehoge;
                //cout << kings_s[i].first << endl;
                //cout << kings_s[i].second << endl;

                string hoge = kings_s[i].first;
                int n = 0;
                for(int j=0;j<s.size();j++) {
                    if(kings_s[i].second == s[j]) {
                        n = j;
                        break;
                    }
                }


                hogehoge.push_back(value_type_i(n,kings_s[i].second));
                while(i+1 < kings_s.size() && kings_s[i].first == kings_s[i+1].first) {
                    i++;
                    string hoge_hoge = kings_s[i].first;
                    int n=0;
                    for(int j=0;j < s.size();j++) {
                        if(kings_s[i].second == s[j]){
                                n = j;
                                break;
                        }
                    }
                    hogehoge.push_back(value_type_i(n,kings_s[i].second));
                }

                sort(hogehoge.begin(),hogehoge.end());

                for(int j=0;j<hogehoge.size();j++) {
                    result.push_back(kings_s[i].first + " " + hogehoge[j].second);
                }
                           

            }

            return result;
        }
広告を非表示にする